Question: my code isnt work Here are the test cases 'use strict'; import * as reducers from ' . / reducers . mjs ' ; test

my code isnt work Here are the test cases 'use strict';
import * as reducers from './reducers.mjs';
test('Test 1. sum of an array of numbers using reducer1',()=>{
expect([1,2,3].reduce(reducers.reducer1)).toBe(6);
});
test('Test 2. reducer1 skips all non-numeric values', ()=>{
expect([1,2, true, 'a',4, true].reduce(reducers.reducer1)).toBe(7);
});
test('Test 3. reducer1 skips a non-numeric value even if it is the first element', ()=>{
expect(['a',1,2,3].reduce(reducers.reducer1)).toBe(6);
});
test('Test 4. reducer1 returns 0 if all the elements are non-numeric', ()=>{
expect(['a','b'].reduce(reducers.reducer1)).toBe(0);
});
test('Test 5. sum of an array of numbers using reducer2',()=>{
expect([1,2,3].reduce(reducers.reducer2)).toBe(6);
});
test('Test 6. reducer2 throws TypeError exception for a non-numeric value', ()=>{
expect(()=>{[1,2, true, 'a',4, true].reduce(reducers.reducer2)}).toThrow(TypeError);
});
test('Test 7. reducer2 throws TypeError exception for a non-numeric value even when it is the first element', ()=>{
expect(()=>{['a',1,2,3].reduce(reducers.reducer2)}).toThrow(TypeError);
}); do you see my attached code? Here it is written out.... /*
* Don't change the declaration of this function.
*/
function reducer1(previousValue, currentValue){
const num = parseFloat(currentValue);
// Check if currentValue is not a number
if (isNaN(num)){
// If currentValue is not numeric, return previousValue unchanged
return previousValue;
}
// Otherwise, add numeric value to previousValue
return previousValue + num;
}
/*
* Don't change the declaration of this function.
*/
function reducer2(previousValue, currentValue){
const num = parseFloat(currentValue);
// Check if currentValue is not a number
if (isNaN(num)){
throw new TypeError('My error message');
}
// Otherwise, add numeric value to previousValue
return previousValue + num;
}
// Don't add or change anything below this comment.
export { reducer1, reducer2};
 my code isnt work Here are the test cases 'use strict';

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!