Smallest Common Multiple - stuck for days

Hey so I’ve been stuck for days in this challenge, seems like my lack of a background in math is taking its toll. As I finally made it to work, it doesn’t pass one of the tests: the one with arguments [1,13] and I can’t figure out why. I’m using firefox and when I test it in debuggers, it work.
Here comes the code:

``````function smallestCommons(arr) {
let newArr = arr.sort((a,b) => a-b);
let divisible = [];
for (let i = newArr[0]; i <= newArr[1]; i++){
divisible.push(i);
}
console.log(divisible + " divisible arr");
let mdc = newArr.reduce((a,b) => {
let resto = 1;
while (resto !== 0){
let resto = b % a;
if (resto > 0){
b = a;
a = resto;
}
}
return a;
});
let mmc = newArr.reduce((a,b) => {
return a*b/mdc;
})
console.log(mmc + " mmc");
let result = ((a) => {
let counter = false;
for (let i = 2, counter = false; counter === false; i++){
let possible = (a*i);
for (let j = 0, counting = 0; j < divisible.length; j++){
if (possible % divisible[j] === 0) {
counting++;
if (counting === divisible.length){
return possible;
}
}
}
}
});
console.log(result(mmc));
return result(mmc);
}
smallestCommons([1,13]);
``````

However inefficient, your code works and passes the tests for me.

Right now, you’re multiplying your mmc for every integer in increasing order and then checking if your current number (`possible`) is divisible by every element in your array (`divisible`).
Let alone you could make the code more readable:
say, use this:
`if (divible.every( x => possible % x === 0) return possible`
``````for (let j = 0, counting = 0; j < divisible.length; j++){
Think of a way to combine your mdc and mmc for each element of your array `divisible`. hThis aricle might help: ttps://stackoverflow.com/questions/147515/least-common-multiple-for-3-or-more-numbers