describe(‘given a unary function’, () => {
test(‘returns a function that returns the same result for the same input’, () => {
const double = n => n * 2;
const _double = memoize(double);
expect(_double(3)).toBe(double(3));
expect(_double(3)).toBe(double(3));
expect(_double(3)).toBe(double(3));
});
test(‘calls the given function only once for the same input’, () => {
let count = 0;
const updateCount = n => count += n;
const _updateCount = memoize(updateCount);
_updateCount(1);
_updateCount(1);
_updateCount(1);
expect(count).toBe(1);
});
});