算法 ★☆☆☆☆☆】【对参数(数字)+1并返回】Return the Next Number from the Integer Passed"/>
【Edabit 算法 ★☆☆☆☆☆】【对参数(数字)+1并返回】Return the Next Number from the Integer Passed
【Edabit 算法 ★☆☆☆☆☆】【对参数(数字)+1并返回】Return the Next Number from the Integer Passed
math
numbers
algebra
Instructions
Create a function that takes a number as an argument, increments the number by +1 and returns the result.
Examples
addition(0) // 1
addition(9) // 10
addition(-3) // -2
Notes
- Don’t forget to return the result.
Solutions
const addition = (num) => num + 1;
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(addition(2), 3, "2 plus 1 equals 3.")
Test.assertEquals(addition(-9), -8, "-8 plus 1 equals -9.")
Test.assertEquals(addition(0), 1, "0 plus 1 equals 1.")
Test.assertEquals(addition(999), 1000, "999 plus 1 equals 1000.")
Test.assertEquals(addition(73), 74, "73 plus 1 equals 74.")
更多推荐
【Edabit 算法 ★☆☆☆☆☆】【对参数(数字)+1并返回】Return the Next Number from the Integer Passed
发布评论