|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
543 bytes
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|---|
| 4 |
|
|---|
| 5 | function memoize(fn, options = {}) {
|
|---|
| 6 | const { cache = new Map(), getCacheKey } = options;
|
|---|
| 7 | const memoizedFn = function (arg) {
|
|---|
| 8 | const key = getCacheKey ? getCacheKey(arg) : arg;
|
|---|
| 9 | if (cache.has(key)) {
|
|---|
| 10 | return cache.get(key);
|
|---|
| 11 | }
|
|---|
| 12 | const result = fn.call(this, arg);
|
|---|
| 13 | cache.set(key, result);
|
|---|
| 14 | return result;
|
|---|
| 15 | };
|
|---|
| 16 | memoizedFn.cache = cache;
|
|---|
| 17 | return memoizedFn;
|
|---|
| 18 | }
|
|---|
| 19 |
|
|---|
| 20 | exports.memoize = memoize;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.