Tell us what’s happening:
Actually my code solve all the test, but I dont know why can’t pass all of them in the problem.
Thanks for help.
Your code so far
function smallestCommons(arr) {
let max= Math.max(...arr)
let min=Math.min(...arr)
let range=getRange(min,max);
let mcm=getMcm(range)
return mcm;
}
function getRange(min,max){
let numbers=[];
for(let i=min;i<=max;i++){
numbers.push(i);
}
console.log(numbers )
return numbers
}
function getMcm(arr){
let biggest=arr[arr.length-1];
let result=null;
while (result===null) {
if(anyHaveModule(biggest,arr)){
biggest++
}else{
result=biggest
}
}
return result;
}
function anyHaveModule(num,range){
for(let i=0;i<range.length;i++){
const divider=range[i];
const module=num%divider
if(module!==0){
return true
}
}
}
smallestCommons([1,5]);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/smallest-common-multiple