maurogestoso
7/13/2017 - 10:17 AM

medium-memoize-9.js

test(‘uses the passed hashFunction to generate keys for the cached results’, () => {
  const add = (a, b) => a + b;
  function commaSeparateArgs () {
    const args = [];
    for (let i = 0; i < arguments.length; i++) {
      args.push(arguments[i]);
    }
    return args.join(‘,’);
  }
  const _add = memoize(add, commaSeparateArgs);
  expect(_add(2, 3)).toBe(5);
  expect(_add(2, 4)).toBe(6);
});