Skip to content

Instantly share code, notes, and snippets.

@pancho508
Last active November 23, 2019 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pancho508/0031a6f557d5a499a42566d7c3116873 to your computer and use it in GitHub Desktop.
Save pancho508/0031a6f557d5a499a42566d7c3116873 to your computer and use it in GitHub Desktop.
Abuse of reduce
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)
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