Hi,
I wonder if someone could give me feedback on my solution. It passes all the tests apart from the last one, and from other posts on this challenge I get the impression that this is about the solution not being efficient enough.
I’ve done coding before but have never been good at maths. How can I improve the solution? It doesn’t depend on an array, which I think is good because no potentially large array of numbers needs to be held in memory (depending on what you input), but perhaps the algorithm isn’t efficient enough if it’s not passing the last test.
(I also read that you can add // noprotect
to get the last test passing, but this doesn’t work for me in any case).
[spoiler]```js
// noprotect
function smallestCommons(arr) {
let low, high, result, isNotMultiple;
[low, high] = arr.sort((a,b) => a-b);
result = high * 2;
do {
isNotMultiple = false;
for (let i = low; i <= high; i++) {
if (result % i !== 0) {
isNotMultiple = true;
result += high;
break;
}
}
} while (isNotMultiple)
return result;
}
smallestCommons([1,5]);
**Browser information:**
User Agent is: Firefox 60.0, Windows.
**Link to the challenge:**
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple/