10 Days of JavaScript (Day 4) HackerRank Solutions #10daysofjavascript
DAY 4: Create a Rectangle Object
Solution >>>
function Rectangle(a, b) {
this.length = a;
this.width = b;
this.perimeter = 2 * (a + b);
this.area = a * b;
}
DAY 4: Count Objects
Solution >>>
function getCount(objects) {
let pairCount = 0;
for (let i = 0; i < objects.length; i++) {
if (objects[i].x === objects[i].y) {
pairCount++;
}
}
return pairCount;
}
DAY 4: Classes
Solution >>>
function Polygon(shape) {
this.type = shape;
this.perimeter = getPerimeter;
}
function getPerimeter() {
return this.type.reduce((a, b) => a + b);
}
Comments
Post a Comment