Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions sumOfPairNumber.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@

let Arr1 = [1, 24, 3, 4, 5, 6,"C", 73, 8, 19];
let Arr2 = {a:1, b:24, c:3, d:4, e:5, f:6, g:73, h:8, i:19};

function sumEven(array) {
let sum = 0
if(Array.isArray(array)){
for(i of array){
if(i % 2 === 0){
sum = sum + i
}
}
return sum;
}
else if (typeof array ==="object") {
for (let key in array){
if (array[key] % 2 === 0){
(sum = sum + array[key])
}
}
return sum;
}
}
console.log(sumEven(Arr1));
console.log(sumEven(Arr2));
/*
* bonus points
*
* same function works for both arrays and objects
*
* if the input is an array return the sum of the pair numbers
*
* if it is an object like this:
*
* obj={
* a:2,
* b:5,
* c:8
* }
*
* return => "a & c have pair values"
*
*/
/**
* write a function that returns the sum of the pair numbers inside an array
*
Expand Down