Skip to content

Instantly share code, notes, and snippets.

@lubien
Last active March 20, 2017 17:09
Show Gist options
  • Save lubien/0033aa828058139086790324ff9b8fc4 to your computer and use it in GitHub Desktop.
Save lubien/0033aa828058139086790324ff9b8fc4 to your computer and use it in GitHub Desktop.
Find the max number in an array using reduce and maxBy
const len = x => x.length
const maxBy = fn => (x, y) => fn(x) > fn(y) ? x : y
console.log(['a', 'ab', 'abc'].reduce(maxBy(len)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment