math
numbers
I have a bucket containing an amount of navy blue paint and I’d like to paint as many walls as possible. Create a function that returns the number of complete walls that I can paint, before I need to head to the shops to buy more.
n
is the number of square meters I can paint.w
andh
are the widths and heights of a single wall in meters.
howManyWalls(100, 4, 5) // 5
howManyWalls(10, 15, 12) // 0
howManyWalls(41, 3, 6) // 2
function howManyWalls(n, w, h) {
return Math.floor(n/(w*h));
}
let Test = (function(){
return {
assertEquals:function(actual,expected){
if(actual !== expected){
let errorMsg = `actual is ${actual},${expected} is expected`;
throw new Error(errorMsg);
}
},
assertSimilar:function(actual,expected){
if(actual.length != expected.length){
throw new Error(`length is not equals, ${actual},${expected}`);
}
for(let a of actual){
if(!expected.includes(a)){
throw new Error(`missing ${a}`);
}
}
}
}
})();
Test.assertEquals(howManyWalls(100, 4, 5), 5)
Test.assertEquals(howManyWalls(10, 15, 12), 0)
Test.assertEquals(howManyWalls(41, 3, 6), 2)
Test.assertEquals(howManyWalls(50, 11, 5), 0)
Test.assertEquals(howManyWalls(1, 1, 1), 1)
// Author: Joshua Señoron