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
javascript 复制代码
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
javascript 复制代码
function calculateFuel(n) {
	let ans = n * 10;
	return ans < 100? 100:ans;
}
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);
            }
        }
    }
})();

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)
相关推荐
Captaincc1 小时前
AI用量v0.1.11更新发布 新增 jusage doctor 诊断指令 托盘展示token 和余额 新增 AutoClaw 支持
前端·后端·vibecoding
君顾11 小时前
上海24小时自助健身房系统开发实战指南:从架构设计到落地部署
java·开发语言·健身房
香菜TTT2 小时前
大模型上下文协议(MCP):AI 应用的“USB-C”接口技术
开发语言·人工智能·经验分享
aramae2 小时前
模拟实现strlen()函数 (C语言)
c语言·开发语言·后端
计算机魔术师3 小时前
德国Wiki被黑后两周,OpenAI终于把模型失控的账本摊开了
前端
kyriewen3 小时前
我让 AI 当面试官面了我一轮:第 3 个追问我就卡住了(附 10 道追问清单)
前端·面试·ai编程
jimy13 小时前
readelf 查看“派生类”的vtable符号
开发语言·c++
IT_陈寒3 小时前
Python的GIL把我坑惨了,多线程跑得比单线程还慢
前端·人工智能·后端
前端snow4 小时前
ai agent --- 多agent框架之图编排引擎-langgraph
前端
竹林8184 小时前
OmniPic Studio v3.2.1 核心技术架构与全平台发版解析文档
前端·浏览器