Skip to content

Commit

Permalink
Memorization → Memoization
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Jun 17, 2017
1 parent 2bcc071 commit 5e99d81
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 29 deletions.
2 changes: 1 addition & 1 deletion docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
* Workflow
* [Lookup table](workflow/lookup-table.md)
* [Math methods](workflow/math.md)
* [Memorization](workflow/memorization.md)
* [Memoization](workflow/Memoization.md)
* [Scope](workflow/scope.md)
* [Variable access](workflow/variable-access.md)
13 changes: 9 additions & 4 deletions docs/workflow/memoization.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Memoization

Just calculate the value of something once and reuse the value. This avoids the cost of recalculating the same value, caching successive calls:
Just calculate the value of something once and reuse the value. This avoids the
cost of recalculating the same value, caching successive calls:

```js
var cache = Object.create(null)
Expand All @@ -12,8 +13,12 @@ var routeName = `${cityOne}${cityTwo}`
if (!cache[routeName]) cache[routeName] = getDistance(cityOne, cityTwo)
```

Notes that first line is `Object.create(null)`. This create a `Object` without `prototype`. because we want a pure object for be used as a Hash Table (with all the [prototypical method](https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/Object/prototype) missing).
Notes the first line: `Object.create(null)`. This create an `Object` without
`prototype`. because we want a pure object to be used as a hash table (with all
the [prototypical methods](https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/Object/prototype) missing).

If you need more control about your cache, you can create it using Map or WeakMap structures. Specially use it when you want to remove items from the cache.
If you need more control of your cache, you can create it using Map or WeakMap
structures. Specially use this when you want to remove items from the cache.

[LRU](https://www.npmjs.com/package/lru) or [mem](https://www.npmjs.com/package/mem) are good high level libraries that implement this technique.
[LRU](https://www.npmjs.com/package/lru) or [mem](https://www.npmjs.com/package/mem)
are good high level libraries that implement this technique.
24 changes: 0 additions & 24 deletions docs/workflow/memorization.md

This file was deleted.

0 comments on commit 5e99d81

Please sign in to comment.