Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
const listSquared = (m, n) => {
let list = [];
for (let i = m; i <= n; i++) {
let divisors = [];
for (let k = 1; k <= i; k++) {
i % k === 0 ? divisors.push(k) : divisors;
}
let sqrt = Math.sqrt(
divisors.reduce((prev, curr) => {
return prev + Math.pow(curr, 2);
}, 0)
);
if (Math.floor(sqrt) === sqrt) {
list.push([i, Math.pow(sqrt,2)]);
}
}
return list;
};
Cache can save values between tests, which significantly speed up later tests.
Really clean solution. Nice work. Agree you probably don't need the cache.
Looking at it now, I think you are correct. I don't remember it now to be honest. It has been a couple of years since I recall doing this...
What is the point of the cache here? If you're looping from m to n, you'll never repeat values. ex: m = 1, 2, 3, 4, 5... n. The code that returns the cache value should never run.
This comment is hidden because it contains spoiler information about the solution
Just remove or comment the sample test case. It's hidden under the sample tests at the bottom.