JS10 Day 4: Create a Rectangle Object

Jmnote (토론 | 기여)님의 2018년 8월 12일 (일) 14:11 판 (새 문서: ==개요== ;<nowiki>JS10 Day 4: Create a Rectangle Object</nowiki> * https://www.hackerrank.com/challenges/js10-throw/problem <source lang='javascript'> 'use strict'; process.stdin....)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요

JS10 Day 4: Create a Rectangle Object
'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    
    main();    
});

function readLine() {
    return inputString[currentLine++];
}
/*
 * Complete the Rectangle function
 */
function Rectangle(a, b) {
    this.length = a;
    this.width = b;
    this.perimeter = 2 * (a+b);
    this.area = a * b;
}
function main() {
    const a = +(readLine());
    const b = +(readLine());
    
    const rec = new Rectangle(a, b);
    
    console.log(rec.length);
    console.log(rec.width);
    console.log(rec.perimeter);
    console.log(rec.area);
}

2 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}