@micro-js/memoize
v1.0.0
Published
Create a function that memoizes the result of a `fn`.
Downloads
9
Readme
memoize
Create a function that memoizes the result of a `fn`.
Installation
$ npm install @micro-js/memoize
Usage
var memoize = require('@micro-js/memoize')
var slow = memoize(function (num) {
var calc = 0
for (var i = 0; i < num; ++i) {
calc += i
}
return calc
})
// slow
slow(100) // => 4950
// fast
slow(100) // => 4950
API
memoize(fn)
fn
- a function to memoize
Returns: memoized function
License
MIT