0038【Edabit ★☆☆☆☆☆】【生成kv对】Pair Management

0038【Edabit ★☆☆☆☆☆】【生成kv对】Pair Management

arrays language_fundamentals

Instructions

Given two arguments, return an array which contains these two arguments.

Examples
makePair(1, 2) // [1, 2]
makePair(51, 21) // [51, 21]
makePair(512124, 215) // [512124, 215]
Notes
  • N/A
Solutions
function makePair(num1, num2) {
    return [num1,num2] ;
}
TestCases
let Test = (function(){
    return {
        assertEquals:function(actual,expected){
            if(actual !== expected){
                let errorMsg = `actual is ${actual},${expected} is expected`;
                throw new Error(errorMsg);
            }
        },
        assertSimilar:function(actual,expected){
            if(actual.length != expected.length){
                throw new Error(`length is not equals, ${actual},${expected}`);
            }
            for(let a of actual){
                if(!expected.includes(a)){
                    throw new Error(`missing ${a}`);
                }
            }
        }
    }
})();

Test.assertSimilar(makePair(1, 2), [1, 2])
Test.assertSimilar(makePair(21, 82), [21, 82])
Test.assertSimilar(makePair(4213, 526), [4213, 526])

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