Algorithm Scripting: Smallest Common Multiple

Intermediate Algorithm Scripting: Smallest Common Multiple

Your code so far

//noprotect
function smallestCommons(arr) {
 
  var start = Math.min(arr[0],arr[1]);
  var end = Math.max(arr[0],arr[1]);
 var range = [];

 

  for (var i= start; i<=end ; i++)
{
range.push(i);
}
  
var LCM = 0,
flag = true;
while(flag){
  LCM++;
  for (var j= start; j <= end;j++){
    if(LCM % j !==0){
      break;
    }
    else if (j===end){
      flag = false;
    }
  }
}
return LCM;
}

i checked my code work well with console but i couldn’t pass the last 2 questions even i added //noprotect in first line.
could anyone give me some advise on it? thanks in advance

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums

You will to make it more efficient, it is too much to handle even with the //noprotect (if that command is working)

1 Like

thanks, i did finally :slight_smile: