ExamGecko
Question list
Search
Search

List of questions

Search

Related questions











Question 2 - Certified JavaScript Developer I discussion

Report
Export

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);
Answers
A.
console.assert(sum3(1, '2')) == 12);
B.
console.assert(sum3(0)) == 0);
Answers
B.
console.assert(sum3(0)) == 0);
C.
console.assert(sum3(-3, 2 )) == -1);
Answers
C.
console.assert(sum3(-3, 2 )) == -1);
D.
console.assert(sum3('hello', 2, 3, 4)) === NaN);
Answers
D.
console.assert(sum3('hello', 2, 3, 4)) === NaN);
Suggested answer: A, C
asked 23/09/2024
Mitesh Patel
32 questions
User
Your answer:
0 comments
Sorted by

Leave a comment first