[SOLVED]Why infinite loop is happening?

[SOLVED]Why infinite loop is happening?
0.0 0

#1
function smallestCommons(arr) {
  var y = Math.max(arr[0],arr[1]);
  var x = Math.min(arr[0],arr[1]);
  var array = [];
  var multiple = [];
  for(var i=x;i<(y+1);i++){
    array.push(i);
  }
  var max=1;
  for(var l=0;l<array.length;l++) max = max*array[l];
  for(var z=y;z<(max+1);z++){
    var check=0;
    for(var w=0;w<array.length;w++){
      var result = z%array[w];
      if(result===0) check++;
      else break;
    }
    if(check===array.length) multiple.push(z);
     
  }
  var final = Math.min.apply(Math,multiple);
  return final;
}// end of function


smallestCommons([23, 18]);

#2

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.


#3

Is it an infinite loop or just so slow that the FCC loop protection thinks it might be an infinite loop?


#4

Yes you are right.My code is working in chrome’s console