Smallest Common Multiple CRASHED my server

Smallest Common Multiple CRASHED my server
0

#1

Smallest Common Multiple crashed my ubuntu laptop server.

No matter which code solution I run from the WIKI page it crashes the server.

the BASIC solution -

function smallestCommons(arr) {
  // Sort array from greater to lowest
  // This line of code was from Adam Doyle (http://github.com/Adoyle2014)
  arr.sort(function(a, b) {
    return b - a;
  });

  // Create new array and add all values from greater to smaller from the
  // original array.
  var newArr = [];
  for (var i = arr[0]; i >= arr[1]; i--) {
    newArr.push(i);
  }

  // Variables needed declared outside the loops.
  var quot = 0;
  var loop = 1;
  var n;

  // Run code while n is not the same as the array length.
  do {
    quot = newArr[0] * loop * newArr[1];
    for (n = 2; n < newArr.length; n++) {
      if (quot % newArr[n] !== 0) {
        break;
      }
    }

    loop++;
  } while (n !== newArr.length);

  return quot;
}

#2

THIS code doesn’t

SPECIAL THANKS GOES TO STEPHEN -

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

  for (var x = min; x <= max; x++) {
    range.push(x);
  }

  var a = Math.abs(range[0]);

    for (var i = 1; i < range.length; i++) {
      var b = Math.abs(range[i]);
      var c = a;

      while (a && b) {
        if (a > b) {
          a %= b;
        }
        else {
          b %= a;
        }
      }
      a = Math.abs(c * range[i] / (a + b));
    }
      return a;
}

 smallestCommons([81,56]);