Skip to content

Instantly share code, notes, and snippets.

@Beraliv
Last active February 3, 2019 14:03
Show Gist options
  • Save Beraliv/db32ec2cda9f2603842344e7708d937d to your computer and use it in GitHub Desktop.
Save Beraliv/db32ec2cda9f2603842344e7708d937d to your computer and use it in GitHub Desktop.
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