Valid JavaScript-Developer-I Dumps shared by ExamDiscuss.com for Helping Passing JavaScript-Developer-I Exam! ExamDiscuss.com now offer the newest JavaScript-Developer-I exam dumps, the ExamDiscuss.com JavaScript-Developer-I exam questions have been updated and answers have been corrected get the newest ExamDiscuss.com JavaScript-Developer-I dumps with Test Engine here:

Access JavaScript-Developer-I Dumps Premium Version
(224 Q&As Dumps, 35%OFF Special Discount Code: freecram)

<< Prev Question Next Question >>

Question 16/56

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

Recent Comments (The most recent comments are at the top.)

Neeraj Gupta - Jul 30, 2024

Option A, B, C are correct.

try the below code: in console.

const sum3 = (arr) => {
if(!arr.length)
{return 0;}

if(arr.length === 1){ return arr[0]
}
if(arr.length === 2) {return arr[0]+ arr[1];}

return arr[0] + arr[1] + arr[2];
}
console.log(sum3([1, '2']));//console.assert(sum3(1, '2')) == 12);
console.log(sum3(['hello', 2, 3, 4]));// console.assert(sum3('hello', 2, 3, 4)) === NaN);
console.log(sum3([0]));//console.assert(sum3(0)) == 0);
console.log(sum3([-3, 2]));//console.assert(sum3(-3, 2 )) == -1);

Priya - Feb 25, 2023

The correct answers are A and B:

A. console.assert(sum3([-3, 2]) == -1);
B. console.assert(sum3([0]) == 0);

Option C is not a valid test because it asserts that the result of sum3([1, '2']) is equal to the string '12', which is not the expected behavior. Option D is also not a valid test because the result of sum3(['hello', 2, 3, 4]) is not NaN, but rather the concatenated string 'hello23'.

jai dixit - Jan 26, 2022

Option A and B are correct.
Option C is incorrect because here we are concatenating 1 and '2' and since 12 == '12' the assertion is true but this does not validate the given function because sum3() is used for finding the sum of the array elements only.

PawelW - Jan 11, 2022

This example is full of missspeling but I managed to clean it and test. Run this code below in node.
const sum3 = (arr) => {
if (!arr.length) return 0;
if (arr.length === 1) return arr[0];
if (arr.length === 2) return arr[0] + arr[1];
return arr[0] + arr[1] + arr[2];
};

console.log(sum3([-3, 2 ])); // -1
console.assert(sum3([-3, 2]) == -1);

console.log(sum3([0])); // 0
console.assert(sum3([0]) == 0);

console.log(sum3([1, '2'])); // '12'
console.assert(sum3([1, '2']) == 12); // '12' == 12 is true

console.log(sum3(['hello', 2, 3, 4])); // hello23
console.assert(sum3(['hello', 2, 3, 4]) === NaN); // Assertion failed

In such case Answeras are A,B,C

ultra instinct - Dec 19, 2021

ans should be A,B

LEAVE A REPLY

Your email address will not be published. Required fields are marked *

Question List (56q)
Question 1: Refer to the code below: new Promise((resolve, reject) =&gt;...
Question 2: Refer to the code below: Let textValue = '1984'; Which code ...
1 commentQuestion 3: Which statement parses successfully?...
3 commentQuestion 4: Refer to the code below: function changeValue(param) { Param...
2 commentQuestion 5: A developer has code that calculates a restaurant bill, but ...
Question 6: Which option is a core Node,js module?...
1 commentQuestion 7: Given the code below: 01 function GameConsole (name) { 02 th...
Question 8: Which statement accurately describes the behaviour of the as...
1 commentQuestion 9: developer wants to use a module named universalContainersLib...
Question 10: A developer wants to leverage a module to print a price in p...
3 commentQuestion 11: Considering type coercion, what does the following expressio...
1 commentQuestion 12: A team that works on a big project uses npm to deal with pro...
Question 13: Refer to HTML below: &lt;p&gt; The current status of an Orde...
1 commentQuestion 14: Refer to code below: Let productSKU = '8675309' ; A develope...
5 commentQuestion 15: Refer to following code block: Let array = [1, 2, 3, 4, 5, 6...
5 commentQuestion 16: A developer needs to test this function: 01 const sum3 = (ar...
1 commentQuestion 17: A developer is required to write a function that calculates ...
3 commentQuestion 18: In the browser, the window object is often used to assign va...
2 commentQuestion 19: Refer to the following code: Let sampleText = 'The quick bro...
Question 20: Which two console logs output NaN? Choose 2 answers | |...
Question 21: developer is trying to convince management that their team w...
2 commentQuestion 22: Refer to the following code that performs a basic mathematic...
1 commentQuestion 23: Refer to the code snippet below: Let array = [1, 2, 3, 4, 4,...
7 commentQuestion 24: Refer to the expression below: Let x = ('1' + 2) == (6 * 2);...
7 commentQuestion 25: A developer has a formatName function that takes two argumen...
2 commentQuestion 26: developer has a web server running with Node.js. The command...
Question 27: Given the following code: Let x =('15' + 10)*2; What is the ...
Question 28: developer publishes a new version of a package with new feat...
1 commentQuestion 29: Refer to the code below: let sayHello = () =&gt; { console.l...
Question 30: Refer to the code below: 01 const server = require('server')...
1 commentQuestion 31: A developer wants to set up a secure web server with Node.js...
Question 32: Consider type coercion, what does the following expression e...
3 commentQuestion 33: The developer wants to test this code: Const toNumber =(strO...
1 commentQuestion 34: Which three statements are true about promises ? Choose 3 an...
Question 35: Refer to code below: Let first = 'who'; Let second = 'what';...
Question 36: A test has a dependency on database. query. During the test,...
Question 37: Universal Containers (UC) just launched a new landing page, ...
Question 38: A test has a dependency on database.query. During the test t...
5 commentQuestion 39: Refer to the following code: function test (val) { If (val =...
Question 40: Refer to the code below: (Exhibit) Line 05 causes an error. ...
Question 41: Which two console logs outputs NaN ? Choose 2 answers...
Question 42: Refer to the code below: Const pi = 3.1415326, What is the d...
5 commentQuestion 43: What is the result of the code block?...
Question 44: Refer to the code below: const addBy = ? const addByEight =a...
1 commentQuestion 45: A developer wrote the following code: 01 let X = object.valu...
2 commentQuestion 46: Refer to code below: Let a ='a'; Let b; // b = a; console.lo...
2 commentQuestion 47: Refer to the following code: 01 function Tiger(){ 02 this.Ty...
Question 48: A developer at Universal Containers creates a new landing pa...
Question 49: Which javascript methods can be used to serialize an object ...
2 commentQuestion 50: A class was written to represent items for purchase in an on...
3 commentQuestion 51: Which three browser specific APIs are available for develope...
Question 52: Refer to HTML below: &lt;div id ="main"&gt; &lt;div id = " c...
2 commentQuestion 53: Refer to the code below: for(let number =2 ; number &lt;= 5 ...
Question 54: Which code statement correctly retrieves and returns an obje...
1 commentQuestion 55: Refer to code below: console.log(0); setTimeout(() =&gt; ( c...
Question 56: Refer to the following code: &lt;html lang="en"&gt; &lt;body...