Exam4Training

Which two assert statements are valid tests for the function?

A developer needs to test this function:

01 const sum3 = (arr) => (

02 if (!arr.length) return 0,

03 if (arr.length === 1) return arr[0],

04 if (arr.length === 2) return arr[0] + arr[1],

05 return arr[0] + arr[1] + arr[2],

06 );

Which two assert statements are valid tests for the function? Choose 2 answers
A . console.assert(sum3(1, ‘2’)) == 12);
B. console.assert(sum3(0)) == 0);
C. console.assert(sum3(-3, 2 )) == -1);
D. console.assert(sum3(‘hello’, 2, 3, 4)) === NaN);

Answer: A,C

Exit mobile version