# *Intermediate Algorithm Scripting: Smallest Common Multiple

Tell us what’s happening:
I want to filter the arrays with Number, but it is giving me undefined, in order to get the first array which only have integer numbers.

``````
function smallestCommons(arr) {

let numRange=[];

for(let i=arr[0];i<=arr[1];i++){

numRange.push(i)
//console.log(i)
}
//console.log(numRange)
let testArr=[];

for(let i=arr[1];i<1000;i=i+arr[1]){

//console.log(i)
for(let j=0;j<=numRange.length;j++){

testArr.push(i/numRange[j])

testArr.filter(e=>e.Number.isInteger())

}

}
return arr;
}

smallestCommons([1,5]);

``````

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36`.

Challenge: Smallest Common Multiple

Why are you pulling array indices in your loop?
` for(let i=arr[0];i<=arr[1];i++)`

1 Like

Because I want the range of numbers which are between the first number of the array and the second number of the array. Then, I want to use them to divide every number multiple of arr[1]. In order to get an array which has only integers numbers. When I get it, it means that number is multiple of every number in the range.

I am trying to get checkedArr =[1,2], but I do not how to do the loop. I am doing this way because I want to to get the divisibles numbers for that one in each index positions of array checkedArr . In this case is only checkedArr =[2]

``````function smallestCommons(arr) {
let newLeftArr= [];
let newRightArr= [];
let newRangeArr=[];

for(let i=arr[0];i<=arr[1];i++){

newRangeArr.push(i)
}
for(let i=1;i<100;i++){

if(arr[0]%i==0) {

newLeftArr.push(i)

}if(arr[1]%i==0)

newRightArr.push(i)
}

// console.log(newLeftArr)
//console.log(newRightArr)
//console.log(newRangeArr)

let splicedArr=newRangeArr.splice(1,(newRangeArr.length-2))

// console.log(splicedArr)

let checkedArr=[];
//splicedArr.length
for(let i=0;i<100;i++){

for(let j=0;j<i;j++){

if(splicedArr[j]%i==0){

checkedArr.push(j)

}

}

}
console.log(checkedArr)
return arr;
}
smallestCommons([1,3]);
``````

It is done. Thanks!

``````function smallestCommons(arr) {
let newLeftArr= [];
let newRightArr= [];
let newRangeArr=[];

for(let i=arr[0];i<=arr[1];i++){

newRangeArr.push(i)
}
for(let i=1;i<100;i++){

if(arr[0]%i==0) {

newLeftArr.push(i)

}if(arr[1]%i==0)

newRightArr.push(i)
}

//console.log(newLeftArr)
//console.log(newRightArr)
//console.log(newRangeArr)

let splicedArr=newRangeArr.splice(1,(newRangeArr.length-2))

// console.log(splicedArr)

let checkedArr=[];
//splicedArr.length
for(let i=0;i<100;i++){

for(let j=0;j<i;j++){

if(splicedArr[j]%i==0){

checkedArr.push(i)

}

}

}
console.log(checkedArr)
return arr;
}
smallestCommons([1,3]);
``````