# Smallest Common Multiple - why doesn't this work?

Can anyone tell me what’s wrong with my logic?

``````
function smallestCommons(arr) {
// variables
let sortedArray = arr.sort( (a, b) => a - b); // sort the array into numerical order
let fullNumericalArray = [];
let gap = sortedArray[1] - sortedArray[0] - 1;
let multiple = sortedArray[0] * sortedArray[1];

// function to fill an array with sequential numbers
function fillArray() {

for (let i = 0; i < gap; i++) {
fullNumericalArray.push(sortedArray[0]+ (i+1));
}

fullNumericalArray.push(sortedArray[1]);
fullNumericalArray.unshift(sortedArray[0]);
}

// function to find smallest common multiple
function findMultiple() {

let arrayIndex = 0
let target = fullNumericalArray.length

while (arrayIndex !== target) {

// if false, increment test multiple by 1, set array index to 0
if((multiple % fullNumericalArray[arrayIndex]) == 0) {

//work out next multiple and assign to variable
let i = multiple + 1;

while(i % sortedArray[0] == 0 && i % sortedArray[1] == 0) {
i += 1;
}

multiple = i;
arrayIndex = 0;
continue
}

// if true, keep test multiple, increment aray index by 1
if((multiple % fullNumericalArray[arrayIndex]) == 0) {
arrayIndex += 1;
continue
}
}
}

// call functions

fillArray();
findMultiple()
console.log(multiple)
return multiple;
}

smallestCommons([1,5]);
``````

User Agent is: `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36`.