• 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
    howManyWalls(100, 4, 5) // 5
    howManyWalls(10, 15, 12) // 0
    howManyWalls(41, 3, 6) // 2
    
    • 1
    • 2
    • 3
    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
    function howManyWalls(n, w, h) {
    	return Math.floor(n/(w*h));
    }
    
    • 1
    • 2
    • 3
    TestCases
    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
  • 相关阅读:
    VS101型单通道振弦传感器采集仪工程安全监测应用及常见问题
    vscode Markdown使用
    【Spring】使用注解开发前提条件
    内存取证入门第二题
    用户数据权利请求响应
    Tilt Five AR桌游体验:概念很新颖,但缺乏高质量内容?
    C++教程(05)——数据类型
    晕,考试的几何画板迭代问题
    2023.5.12解决Ubuntu中ens33没有ip
    Xinetd服务介绍
  • 原文地址:https://blog.csdn.net/avenccssddnn/article/details/134360646