Skip to content

Instantly share code, notes, and snippets.

@ufocoder
Last active January 20, 2019 11:53
Show Gist options
  • Save ufocoder/3ea23f8414c0cf0320f96134023640b5 to your computer and use it in GitHub Desktop.
Save ufocoder/3ea23f8414c0cf0320f96134023640b5 to your computer and use it in GitHub Desktop.

Revisions

  1. ufocoder revised this gist Jan 20, 2019. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion memoized.js
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,6 @@ const memoized = fn => {
    if (!cache.has(args)) {
    cache.set(args, fn(...args))
    }

    return cache.get(args)
    }
    }
  2. ufocoder created this gist Jan 20, 2019.
    10 changes: 10 additions & 0 deletions memoized.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    const memoized = fn => {
    const cache = new WeakMap()
    return (...args) => {
    if (!cache.has(args)) {
    cache.set(args, fn(...args))
    }

    return cache.get(args)
    }
    }