challenge-algorithms-v2.0-m.../07-sumEven/index.js

13 lines
239 B
JavaScript

export function sumEven(value) {
if (value.length == 0 || value.length == 1) return 0;
let result = 0;
value.forEach((item, index) => {
if (item % 2 == 0) {
return (result = result + item);
}
});
return result;
}