-
-
Save seisvelas/b3e01989062b3ce7f11e673d8f79afd4 to your computer and use it in GitHub Desktop.
I wrote these at Pancho's to show him how ridiculously versatile .reduce() can be.
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