Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Salesforce Exam Javascript Developer I Topic 3 Question 73 Discussion

Actual exam question for Salesforce's Javascript Developer I exam
Question #: 73
Topic #: 3
[All Javascript Developer I Questions]

A developer needs to test this function:

01const sum3 = (arr) => (

02if (!arr.length) return 0,

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

04if (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

Show Suggested Answer Hide Answer
Suggested Answer: B

Contribute your Thoughts:

Mammie
4 days ago
I'd go with B and C. The function seems to handle the basic cases, but it's always good to test the boundary conditions too.
upvoted 0 times
...
Tyra
7 days ago
Haha, D is a good one! Imagine passing a string to a function that expects numbers. The developer should really add more edge cases to their tests.
upvoted 0 times
...
Yaeko
8 days ago
D is definitely not valid, as the function expects an array and the input has strings. A might work, but I'm not sure if the function will handle non-numeric inputs correctly.
upvoted 0 times
...
Nickolas
17 days ago
I think B and C are the valid assert statements. The function should handle empty arrays, single-element arrays, and two-element arrays correctly.
upvoted 0 times
Melissa
2 days ago
B) console.assert(sum3(0)) == 0)
upvoted 0 times
...
...
Brigette
19 days ago
I also think option D) console.assert(sum3('hello', 2, 3, 4)) === NaN) is a valid test because it includes non-numeric values.
upvoted 0 times
...
Bettyann
22 days ago
I agree with Nell. Option B makes sense because it tests the function with an empty array.
upvoted 0 times
...
Nell
25 days ago
I think option B) console.assert(sum3(0)) == 0) is a valid test.
upvoted 0 times
...

Save Cancel