The goal of this task is to limit the number of different solutions are valid for the Concept Exercise "Coordinate Transformation".
As a refresher, or first time read, the docs can be found here:
Currently, the final task asks to write a memoize function, that only memoizes the last result.
However, the tests don't enforce that final limitation. Technically memoizing all calls is fine if you look at the grammar pedantically (it's undefined), but the many many ways to build a cache make it harder to write automated analyzers for, and we really want to force people to use let (or var) here.
Solution that should not pass (but passes)
export function memoizeTransform(f) {
const cache = {}
return function memoize(x, y) {
const key = `${x}:${y}`
return cache[key] || cache[key] = f(x, y)
}
}
Solution that should pass (and passes)
export function memoizeTransform(f) {
let lastX, lastY, lastResult
return function memoize(x, y) {
if (x === lastX && y === lastY) {
return lastResult
}
lastX = x
lastY = y
return lastResult = f(x, y)
}
}
The goal of this task is to limit the number of different solutions are valid for the Concept Exercise "Coordinate Transformation".
As a refresher, or first time read, the docs can be found here:
Currently, the final task asks to write a
memoizefunction, that only memoizes the last result.However, the tests don't enforce that final limitation. Technically memoizing all calls is fine if you look at the grammar pedantically (it's undefined), but the many many ways to build a cache make it harder to write automated analyzers for, and we really want to force people to use
let(orvar) here.Solution that should not pass (but passes)
Solution that should pass (and passes)