0035【Edabit ★☆☆☆☆☆】【两数组成十】Two Makes Ten

0035【Edabit ★☆☆☆☆☆】【两数组成十】Two Makes Ten

algorithms conditions validation

Instructions

Create a function that takes two arguments. Both arguments are integers, a and b. Return true if one of them is 10 or if their sum is 10.

Examples
makesTen(9, 10) // true
makesTen(9, 9) // false
makesTen(1, 9) // true
Notes
  • Don’t forget to return the result.
Solutions
function makesTen(a, b) {
    return a==10 || b == 10 || (a+b) == 10 ;
}
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(makesTen(9, 10), true)
Test.assertEquals(makesTen(9, 9), false)
Test.assertEquals(makesTen(1, 9), true)
Test.assertEquals(makesTen(10, 1), true)
Test.assertEquals(makesTen(10, 10), true)
Test.assertEquals(makesTen(8, 2), true)
Test.assertEquals(makesTen(8, 3), false)
Test.assertEquals(makesTen(10, 42), true)
Test.assertEquals(makesTen(12, -2), true)

你可能感兴趣的:(#,Edabit,javascript,算法)