0068【Edabit ★☆☆☆☆☆】I‘d Like a New Shade of Blue, Please

0068【Edabit ★☆☆☆☆☆】I'd Like a New Shade of Blue, Please

math numbers

Instructions

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 and h are the widths and heights of a single wall in meters.
Examples
javascript 复制代码
howManyWalls(100, 4, 5) // 5
howManyWalls(10, 15, 12) // 0
howManyWalls(41, 3, 6) // 2
Notes
  • Don't count a wall if I don't manage to finish painting all of it before I run out of paint.
  • All walls will have the same dimensions.
  • All numbers will be positive integers.
Solutions
javascript 复制代码
function howManyWalls(n, w, h) {
	return Math.floor(n/(w*h));
}
TestCases
javascript 复制代码
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
相关推荐
Fate_I_C1 分钟前
Kotlin 中的 suspend(挂起函数)
android·开发语言·kotlin
周亚鑫3 分钟前
vue3 js代码混淆
开发语言·javascript·ecmascript
努力学算法的蒟蒻3 分钟前
day49(12.30)——leetcode面试经典150
算法·leetcode·面试
天赐学c语言3 分钟前
12.30 - 合并区间 && C++中class和C语言中struct的区别
c语言·c++·算法·leecode
陳103010 分钟前
C++:vector(1)
开发语言·c++
棉晗榜10 分钟前
WPF将程序集里面嵌入的资源文件下载到本机磁盘中,将项目中的文件下载到桌面
开发语言·wpf
人道领域17 分钟前
【零基础学java】(Map集合)
java·开发语言
杀死那个蝈坦18 分钟前
JUC并发编程day1
java·开发语言
lly20240619 分钟前
SQLite Alter 命令详解
开发语言
沃斯堡&蓝鸟19 分钟前
DAY33 类的装饰器
开发语言·python