Last active
February 3, 2019 14:03
-
-
Save Beraliv/db32ec2cda9f2603842344e7708d937d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const isEven = value => value % 2 === 0; | |
const coreJs = array => { | |
// starts from 0 | |
let sum = 0; | |
// iterates over array | |
for (let i = 0; i < array.length; i++) { | |
// transforms value to value + 1 | |
const result = array[i] + 1; | |
// ignores odd values | |
if (isEven(result)) { | |
// applies addition | |
sum += result; | |
} | |
} | |
return sum; | |
}; | |
const ages = [16, 23, 24] | |
coreJs(ages) // 24 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment