<commit_before># Memoization: Caching successive calls

Just calculate the value of something once and reuse the value. This avoids the cost of recalculating the same value.

```js
var cache = Object.create(null)
var cityOne = 'Murcia'
var cityTwo = 'Madrid'
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).

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.

[LRU](https://www.npmjs.com/package/lru) or [mem](https://www.npmjs.com/package/mem) are good high level libraries that implement this technique.<commit_msg>Update memoization.md<commit_after># Memoization: Caching successive calls

Just calculate the value of something once and reuse the value. This avoids the cost of recalculating the same value.

```js
var cache = Object.create(null)

var cityOne = 'Murcia'
var cityTwo = 'Madrid'
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).

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.

[LRU](https://www.npmjs.com/package/lru) or [mem](https://www.npmjs.com/package/mem) are good high level libraries that implement this technique.
{'fraction_non_alphanumeric': 0.10136157337367625, 'fraction_numerical': 0.0, 'mean_word_length': 5.1234567901234565, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 6, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3065817', 'n_tokens_mistral': 593, 'n_tokens_neox': 556, 'n_words': 230}