Tell us what’s happening:
After last challenge i suspect that my code not efficient for FCC again - i got 4 of 6 passes and it looks like because of slow process of very long iteration i don’t get passes for big numbers. Am i right or it is just mistakes in code - not his inneficiency? And how to understand that your code slow and inefficient?
Your code so far
function smallestCommons(arr) {
arr = arr.sort((a,b) => {return a - b});
let nar = [];
for (var i = arr[0]; i <= arr[1]; i++) {
nar.push(i);
}
let check = 0;
let result;
var j = nar[0]*nar[nar.length-1];
for (j; check !== nar.length; j++) {
check = 0;
for (var k = 0; k < nar.length; k++) {
if (Number.isInteger(j/nar[k])) {
check++;
}
if (check === nar.length) {
result = j;
}
}
}
return result;
}
smallestCommons([18,23]);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple