# Smallest Common

Tell us what’s happening:
Hello again friends,
the code works for `[5,1]` and `[2,10]`, and dont work for `[23, 18]` and `[1, 13]`, I dont know why?
after a few days of reflection -_- , this is what I find, and I would like to share it with the community.

the objective is to create an array containing multiples of the given elements,
I took table 0(`mult[0]`), as a reference for comparison with the others 1+,
at each test, if the multiple not found we call the `addmult()` function to add the next element in the array to test it, and so on…
`Help please ^^`

``````
function smallestCommons(arr) {
var mult = [];
var elem = [];
var sum = 0;
//create an array "elem[]" of elements (from arr[0] to arr[1]) that we look at thier multiples and I whoud like to have them in ascendent order
if (arr[0]<arr[1]){
for (let i=arr[0]; i<=arr[1]; i++){
elem.splice(i,1,i)}
}else{
for (let i=arr[1]; i<=arr[0]; i++){
elem.splice(i,1,i)}
};
//function to create a first array contine multiples of all elements of elem[]
function multArr(n){
for (let i=0; i<elem.length; i++){
mult[i]=[];
for (let j=0; j<=n; j++){
sum = sum +elem[i]
mult[i].push(sum);
}
sum = 0;
}
}
// function to add multiples to the array while smallestCommons didn't fined
for(let i=0; i<arr.length; i++){
arr[i].push((arr[i][mult[i].length-1])+elem[i]);
}
}
var result = 0;
var m = 2;
var i = 1;
var j = 0;
multArr(m);
//this is the main loop, the idea is to create array of multiples untile we find the common number
//test CommonMultipl
while(i < mult.length){
if (mult[i].includes(mult[0][j]) == false) {
i = 1;
j++;
} else {
i++;
result = mult[0][j];
}
}
return result;
}
console.log(smallestCommons([2,10]));//2520```