📜  查找最小公倍数 javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:46.283000             🧑  作者: Mango

代码示例1
function smallestCommons(arr) {
  var multiple = [];
   arr.sort(function(a, b){
    return a - b;
    
  });
  var range = (start, stop, step) => Array.from({ length: (stop - start) / step + 1}, (_, i) => start + (i * step));
  multiple =range(arr[0], arr[1], 1)
  
  let max = Math.max(...multiple)
  
  const small = (current) => n % current === 0;
  let n = max * (max - 1)
  let common = false;
  common = multiple.every(small)
  while(common === false){
    n++
    common = multiple.every(small)
  }
  
  return n
}
smallestCommons([1,5]); //returns 60