Hello back, i think my new code is â€śbetterâ€ť. In my solution, i create an array with the first 10 values (0-9).

If i find my solution in these 10 possibilities, it return my result.

For exemple, here for [1, 3], it return me 6 because it is in the first 10 possibilities.

But if itâ€™s not the case, i save my last value from my multidimentional array. Then i delete all the value from my original array. And i start to re-fill my array with 10 next new values. I do it and if it succefully find my result, i get out.

I tried to find a way to have some thing dynamic and not to much cpu heavyâ€¦

But my problem is i have issue toâ€¦get out

```
/*
Link: https://beta.freecodecamp.org/en/challenges/intermediate-algorithm-scripting/smallest-common-multiple
*/
function smallestCommons( arr ) {
let min = Math.min.apply( Math, arr ); //1
let max = Math.max.apply( Math, arr ); //3
let minCopy = min;
let maxCopy = max;
let myArray = [ [min, max] ];
let myNewArray = [];
//global variable
bool = false;
//global variable
boolOutWhile = false;
//I create my original array with the first 10 values (0-9)
for( let k = 0; k < 9; k++ ) {
myArray.push( [minCopy = minCopy+min, maxCopy = maxCopy+max]);
}
do {
//I make a copy of the last value of my array for later
myNewArray.push( myArray[myArray.length-1] ); //[10, 30]
let lastValueMin = myNewArray[myNewArray.length-1][0]; //10
let lastValueMax = myNewArray[myNewArray.length-1][1]; //30
let myArrayL = myArray.length; //10
//Two 'foor-loop' to check every value from myArray[k] with myArray[][x]
for( k = 0; k < myArrayL; k++ ) {
for( let x = 0; x < myArrayL; x++ ) {
//If i have a match then
if( myArray[k][0] == myArray[x][1] ) {
//I make a copy of the number matching for my next 'for loop' interval (here: 3, 6 and 9 matches)
valueCopy = myArray[x][1];
/*
3 is EQUAL to 3
6 is EQUAL to 6
9 is EQUAL to 9
*/
// console.log( myArray[k][0]+" is EQUAL to "+myArray[x][1]);
/*
It's 1 and 3 because the interval is between min(1) and max(3)
3/1=(3) 3/2(1.5) 3/3=(1)// 6/1=(6) 6/2=(3) 6/3=(2) // 9/1=(9) 9/2=(4.5) 9/3=(3)
*/
for( let i = min; i <= max; i++ ) {
//If my valueCopy / i (3/1, 3/2, 3/3...) is not an Integer then i stop
if( Number.isInteger( valueCopy / i ) == false ) {
bool = false;
i = max;
//else, my bool have a value of 'true'
}else {
bool = true;
}
}
//If my bool still have a value of true at the end of the last 'for-loop' then it's done
if( bool == true ) {
//i can get out of the 'while-loop'
boolOutWhile = true;
//return my result
return valueCopy;
}
}
}
}
//delete my useless value to do it again
myArray.splice(0);
myNewArray.splice(0);
//re-fill my array with new values from the end of my last ten first array values
/*
For exemple, if 6 was not the value to return for 1-3, then i would have:
[
[11, 33], [12, 36], [13, 39], [14, 42], [...], [20, 60]
]
*/
for( k = 0; k <= 9; k++ ) {
myArray.push( [lastValueMin = lastValueMin+min, lastValueMax = lastValueMax+max]);
}
}while( boolOutWhile == false );
};
// console.log( smallestCommons( [1,3] ) ); //find 6
//console.log( smallestCommons( [1,5] ) ); //failed
```