Skip to content

Instantly share code, notes, and snippets.

@juliobetta
Last active December 9, 2020 01:57
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 juliobetta/42cfdaac74de1cac572b78b51ad3a0f1 to your computer and use it in GitHub Desktop.
Save juliobetta/42cfdaac74de1cac572b78b51ad3a0f1 to your computer and use it in GitHub Desktop.
const hasDebutAfter1980 = character => character.debut > 1980;
const withFind = characters.find(hasDebutAfter1980);
const withReduce = characters.reduce((accumulator, character) => {
if(hasDebutAfter1980(character) && !accumulator) {
return character;
}
return accumulator;
}, null);
// { name: "Donkey Kong", debut: 1981 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment