find least common multiple javascript
function smallestCommons(arr) {
var max = Math.max(...arr);
var min = Math.min(...arr);
var candidate = max;
var smallestCommon = function(low, high) {
// inner function to use 'high' variable
function scm(l, h) {
if (h % l === 0) {
return h;
} else {
return scm(l, h + high);
}
}
return scm(low, high);
};
for (var i = min; i <= max; i += 1) {
candidate = smallestCommon(i, candidate);
}
return candidate;
}
smallestCommons([5, 1]); // should return 60
smallestCommons([1, 13]); // should return 360360
smallestCommons([23, 18]); //should return 6056820
Also in JavaScript:
- javascript use variable regex
- js clone array
- axios js and react
- react materialize cdn
- scroll to bottom of div javascript
- loop through checkboxes jquery
- format currency javascript
- javascript get div x y position
- javascript Count the frequency of a value in an array
- import switch material ui
- function expression
- access json python
- install vue-cli
- how to scroll down to the bottom of a div using javascript
- click a link using jquery
- binary to ascii javascript
- fetch js
- how to run a vue js hello world app in vue version 3
- download image in nodejs
- What is the correct JavaScript syntax for opening a new window called "w2" ?
- js index sorted
- datepicker select date programmatically bootstrap
- check if anagram
- ngingx proxy express get real ip