Skip to content

Instantly share code, notes, and snippets.

@joaofnds
Last active November 17, 2018 20:22
Show Gist options
  • Select an option

  • Save joaofnds/f9a3b46cf403f2881ca5acff248216a8 to your computer and use it in GitHub Desktop.

Select an option

Save joaofnds/f9a3b46cf403f2881ca5acff248216a8 to your computer and use it in GitHub Desktop.
Simple js helpers (range, log, logFunc)
const fib =
n =>
n < 2
? 1
: fib(n - 1) + fib(n - 2)
const range =
(min, max) =>
Array(max - min + 1).fill().map((_, i) => i + min)
const log = value => console.log(value) || value
const logFunc = func => (...args) => log(func(...args))
const memoize =
(func, mem = {}) =>
(...args) => {
const key = JSON.stringify(args);
mem[key] = mem[key] || func(...args)
return mem[key];
}
const memfib = memoize(fib)
range(0, 10).forEach(logFunc(memfib))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment