本文主要是介绍【Edabit 算法 ★☆☆☆☆☆】 Is the Number Less than or Equal to Zero?,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
【Edabit 算法 ★☆☆☆☆☆】 Is the Number Less than or Equal to Zero?
language_fundametals
validation
conditions
Instructions
Create a function that takes a number as its only argument and returns
true
if it’s less than or equal to zero, otherwise returnfalse
.
Examples
lessThanOrEqualToZero(5) // false
lessThanOrEqualToZero(0) // true
lessThanOrEqualToZero(-2) // true
Notes
- Don’t forget to return the result.
Solutions
function lessThanOrEqualToZero(num) {return num <= 0 ;
}
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(lessThanOrEqualToZero(5), false)
Test.assertEquals(lessThanOrEqualToZero(0), true)
Test.assertEquals(lessThanOrEqualToZero(-5), true)
这篇关于【Edabit 算法 ★☆☆☆☆☆】 Is the Number Less than or Equal to Zero?的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!