Fundamentals
Arrays
Data Types
function findOnly(arr) { let result = 0; arr.forEach((i) => { result = i ^ result; }); return result; }
function getSum(array) {return array.reduce((total, num) => total += num);- function findOnly(arr) {
- let result = 0;
- arr.forEach((i) => {
- result = i ^ result;
- });
- return result;
- }
Test.assertEquals(findOnly([1,2,3,1,2,3,4]), 4, "looks like its wrong."); Test.assertEquals(findOnly([5,5,6,6,1,15,15,10,10]), 1, "looks like its wrong."); Test.assertEquals(findOnly([-1,-1,-1,10,15,10,15]), -1, "looks like its wrong.");
Test.assertEquals(getSum([5,9,4,1]), 19, "looks like its wrong.");Test.assertEquals(getSum([4,0,4,50,8]), 66, "looks like its wrong.");Test.assertEquals(getSum([5,9,4,1,9,1,1,1,4,10]), 45, "looks like its wrong.");- Test.assertEquals(findOnly([1,2,3,1,2,3,4]), 4, "looks like its wrong.");
- Test.assertEquals(findOnly([5,5,6,6,1,15,15,10,10]), 1, "looks like its wrong.");
- Test.assertEquals(findOnly([-1,-1,-1,10,15,10,15]), -1, "looks like its wrong.");