• 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
  • 相关阅读:
    一个Linux主机巡检脚本
    react源码分析:深度理解React.Context
    YOLO系列之yolov2解读(2)
    JSON数据格式
    物联网整体框架有哪些层面?
    云贝教育 |【PostgreSQL PGCA】pg15安装pg_hint_plan扩展包
    uni-app集成mui-player
    数据结构一
    python中的图像增强技术
    Eureka处理流程
  • 原文地址:https://blog.csdn.net/avenccssddnn/article/details/134360646