Last active
November 23, 2019 23:03
-
-
Save pancho508/0031a6f557d5a499a42566d7c3116873 to your computer and use it in GitHub Desktop.
Abuse of reduce
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 range = (n) => [...Array(n).keys()]; | |
const fib = (n) => range(n).slice(1).reduce( | |
(acc, value) => { | |
console.log([acc[1], acc[0]+acc[1]]); | |
return [acc[1], acc[0]+acc[1]] | |
} | |
, [0, 1])[0] | |
fib(5) |
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 mexicanWave = (str) => | |
str.split("").reduce( (acc, value, index, array) => { | |
let wavedStr = array.concat(); | |
wavedStr[index] = wavedStr[index].toUpperCase() | |
return acc.concat(wavedStr.join("")) | |
}, []) | |
mexicanWave("lol") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment