Tell us what’s happening:
Hay, guys, I’ve stumbled upon this problem. It passes all the tests, except the last one for some reason: smallestCommons([23, 18])
should return 6056820.
It works in browser console though
Your code so far
function smallestCommons(arr) {
const sortedArr = arr.sort((a, b) => a - b)
const dividersArr = createDividersArr(sortedArr[0], sortedArr[1])
let smallestCommonNumber;
for (let i = 0; !smallestCommonNumber; i++) {
smallestCommonNumber = isDividedByAllNumInArr(dividersArr, i) ? i : undefined
}
return smallestCommonNumber
}
function createDividersArr(min, max) {
const arr = []
for (let i = min; i <= max; i++) {
arr.push(i)
}
return arr
}
function isDividedByAllNumInArr(arr, num) {
return arr.every(el => {
return num % el === 0
})
}
smallestCommons([23, 18])
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple/