Last active
March 20, 2017 17:09
-
-
Save lubien/0033aa828058139086790324ff9b8fc4 to your computer and use it in GitHub Desktop.
Find the max number in an array using reduce and maxBy
This file contains 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 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