本文主要是介绍【Edabit 算法 ★☆☆☆☆☆】【求Golf撞击因子】Smash Factor,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
【Edabit 算法 ★☆☆☆☆☆】【求Golf撞击因子】Smash Factor
math
numbers
Smash factor is a term in golf that relates to the amount of energy transferred from the club head to the golf ball. The formula for calculating smash factor is ball speed divided by club speed.
Create a function that takes ball speed bs and club speed cs as arguments and returns the smash factor to the nearest hundredth.
Examples
smashFactor(139.4, 93.8) // 1.49
smashFactor(181.2, 124.5) // 1.46
smashFactor(154.7, 104.3) // 1.48
Notes
- Remember to round to the nearest hundredth.
- All values will be valid (so no dividing by zero).
Solutions
const smashFactor = (bs, cs)=>{return Math.round(bs/cs*100)/100
}
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(smashFactor(139.4, 93.8), 1.49)
Test.assertEquals(smashFactor(181.2, 124.5), 1.46)
Test.assertEquals(smashFactor(154.7, 104.3), 1.48)
这篇关于【Edabit 算法 ★☆☆☆☆☆】【求Golf撞击因子】Smash Factor的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!