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
2 months 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
Gilberto
9 days ago
User 3: B) console.assert(sum3(0)) == 0) and C) console.assert(sum3(-3, 2 )) == -1) are the way to go.
upvoted 0 times
...
Nicolette
21 days ago
User 2: Yeah, testing the basic cases and boundary conditions is important.
upvoted 0 times
...
Twila
1 months ago
User 1: I think B and C are the valid tests.
upvoted 0 times
...
...
Tyra
2 months 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
2 months 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
2 months 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
Amber
22 days ago
C) console.assert(sum3(-3, 2 )) == -1)
upvoted 0 times
...
Mauricio
1 months ago
B) console.assert(sum3(0)) == 0)
upvoted 0 times
...
Charolette
1 months ago
C) console.assert(sum3(-3, 2 )) == -1)
upvoted 0 times
...
Melissa
2 months ago
B) console.assert(sum3(0)) == 0)
upvoted 0 times
...
...
Brigette
2 months 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
2 months ago
I agree with Nell. Option B makes sense because it tests the function with an empty array.
upvoted 0 times
...
Nell
2 months ago
I think option B) console.assert(sum3(0)) == 0) is a valid test.
upvoted 0 times
...

Save Cancel