perun24
1
I am not sure what’s wrong with my code. All other tests have passed apart from this one. Can somebody please help.
export function memoizeTransform(f) {
let prevX, prevY, prevResult;
return (x, y) => {
if (prevX === x && prevY === y) {
return prevResult;
} else {
prevX = x;
prevY = y;
prevResult = f(x, y)
return prevResult;
}
}
}
glennj
2
Please show the test results. There are 6 tests for memoization, which ones are failing?
perun24
3
Here’s the test result
const memoizedTranslate = memoizeTransform(translate2d(1, 2));
expect(memoizedTranslate(2, 2)).toEqual([3, 4]);
expect(memoizedTranslate(6, 6)).toEqual([7, 8]);
Test Failure
Error: expect(received).toEqual(expected) // deep equality
- Expected - 2
+ Received + 2
Array [
- 7,
- 8,
+ 9,
+ 10,
]
perun24
4
Thanks, managed to solve it, it was a syntax error.