本文主要是介绍【Edabit 算法 ★☆☆☆☆☆】Return the Remainder from Two Numbers,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
【Edabit 算法 ★☆☆☆☆☆】Return the Remainder from Two Numbers
math
numbers
Instructions
There is a single operator in JavaScript, capable of providing the remainder of a division operation. Two numbers are passed as parameters. The first parameter divided by the second parameter will have a remainder, possibly zero. Return that value.
Examples
remainder(1, 3) // 1
remainder(3, 4) // 3
remainder(-9, 45) // -9
remainder(5, 5) // 0
Notes
- The tests only use positive and negative integers.
- Don’t forget to return the result.
Solutions
function remainder(x, y) {return x % y ;
}
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(remainder(7, 2), 1)
Test.assertEquals(remainder(3, 4), 3)
Test.assertEquals(remainder(-9, 45), -9)
Test.assertEquals(remainder(5, 5), 0)
这篇关于【Edabit 算法 ★☆☆☆☆☆】Return the Remainder from Two Numbers的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!