当前位置: 首页 > article >正文

0036【Edabit ★☆☆☆☆☆】【让我加油】Let‘s Fuel Up!

0036【Edabit ★☆☆☆☆☆】【让我加油 】Let’s Fuel Up!

control_flow language_fundamentals numbers

Instructions

A vehicle needs 10 times the amount of fuel than the distance it travels. However, it must always carry a minimum of 100 fuel before setting off.

Create a function which calculates the amount of fuel it needs, given the distance.

Examples
calculateFuel(15) // 150
calculateFuel(23.5) // 235
calculateFuel(3) // 100
Notes
  • Distance will be a number greater than zero.
  • Return 100 if the calculated fuel turns out to be less than 100.
Solutions
function calculateFuel(n) {
	let ans = n * 10;
	return ans < 100? 100:ans;
}
TestCases
let Test = (function(){
    return {
        assertEquals:function(actual,expected){
            if(actual !== expected){
                let errorMsg = `actual is ${actual},${expected} is expected`;
                throw new Error(errorMsg);
            }
        }
    }
})();

Test.assertEquals(calculateFuel(15), 150)
Test.assertEquals(calculateFuel(23), 230)
Test.assertEquals(calculateFuel(10), 100)
Test.assertEquals(calculateFuel(3), 100)
Test.assertEquals(calculateFuel(23.5), 235)
Test.assertEquals(calculateFuel(3.14), 100)
Test.assertEquals(calculateFuel(9.99999), 100)
Test.assertEquals(calculateFuel(822315322), 8223153220)
Test.assertEquals(calculateFuel(12345.6789), 123456.789)
Test.assertEquals(calculateFuel(31.41), 314.1)

http://www.kler.cn/a/105053.html

相关文章:

  • 项目管理之如何有效定义项目目标
  • Android12 启动页适配
  • PX4天大bug,上电反复重启,连不上QGC!
  • 【openGauss】一主一备实现主备节点切换实验(switchover、failover)
  • 2023全新TwoNav开源网址导航系统源码 | 去授权版
  • MySQL数据库备份实战
  • 打破总分行数据协作壁垒,DataOps在头部股份制银行的实践|案例研究
  • KMS在腾讯云的微服务实践助力其降本50%
  • 单例模式及其使用场景
  • RSAUtil 前端 JavaScript JSEncrypt 实现 RSA (长文本)加密解密
  • 【20年VIO梳理】
  • SpringMVC 异常处理器
  • 详解Java堆的应用场景,思路分析,代码实现
  • 9.(vue3.x+vite)组件间通信方式之EventBus
  • cmd 命令关闭占用端口
  • 从0开始学云计算之服务器:服务的定义,特点,应用场景,分类
  • AFsim编译-Windows
  • Ubuntu22.04安装,SSH无法连接
  • 数据可视化报表分享:区域管理驾驶舱
  • 如何利用验证链技术减少大型语言模型中的幻觉