Skip to content

Instantly share code, notes, and snippets.

@blended-ideas
Last active February 21, 2019 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blended-ideas/810c6bad7ca72240655308d4492ab662 to your computer and use it in GitHub Desktop.
Save blended-ideas/810c6bad7ca72240655308d4492ab662 to your computer and use it in GitHub Desktop.
# Cassidoo Newsletter Challenge - 2/21/19
removeForOdd = (arr) => {
const sum = arr.reduce((a, b) => a + b);
if (sum % 2 !== 0) {
return -1;
}
return arr.findIndex(x => x % 2 !== 0);
}
# Same thing in a line. Coz, why not?
removeForOdd = arr => arr.reduce((a, b) => a + b) % 2 !== 0 ? -1 : arr.findIndex(x => x % 2 !== 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment