I’ve submitted the following code for this challenge, but for some reason when I submit it the final test (smallestCommons([23, 18]) doesn’t pass. However, when I run this code in the console all of the expected results are returned. I don’t think it has anything to do with how I get my rangeArr into numerical order, because the code worked for the smallestCommons[5, 1]), which is out of order similar to the test that I’m failing.
Can anyone lend a helping hand as to why this is happening?
Thanks.
function smallestCommons(arr) {
let rangeArr = [];
for (let x = Math.min(…arr); x <= Math.max(…arr); x++) {
rangeArr.push(x);
}
let who = “”;
for (let x = 0; who == “”; x++) {
if (rangeArr.every(y => x % y == 0) == true) {
who = x;
}
}
return who;
}