Tell us what’s happening:
All the tests in this challenge pass, expect the final one:
smallestCommons([23, 18])
should return 6056820.
But when I run the code in the console it does in fact return 6056820. What am I doing wrong?
Your code so far
function smallestCommons(arr) {
const rangedArr = getRangeBetween(orderArr(arr));
let i = 1;
while (true) {
if (
rangedArr
.map(val => i % val == 0)
.reduce((preVal, curVal) => preVal && curVal)
) return i;
i++;
}
}
function orderArr(arr) {
return arr.sort((a, b) => b - a);
}
function getRangeBetween(arr) {
let rangedArr = [];
for (let i = arr[0]; i >= arr[1]; i--) {
rangedArr.push(i);
}
return rangedArr;
}
smallestCommons([23, 18]);
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36 OPR/60.0.3255.95
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple