Skip to content

Instantly share code, notes, and snippets.

@rosshadden
Created May 24, 2017 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rosshadden/1963312ad12863263c24d26689e4e33f to your computer and use it in GitHub Desktop.
Save rosshadden/1963312ad12863263c24d26689e4e33f to your computer and use it in GitHub Desktop.
function gcd (x, y) {
let _gcd = (a, b) => (b === 0 ? a : _gcd(b, a % b));
return _gcd(Math.abs(x), Math.abs(y));
}
function lcm (x, y) {
return (x === 0 || y === 0) ? 0 : Math.abs(Math.floor(x / gcd(x, y)) * y);
}
function minQuantity(values = []) {
values = values.map((n) => Math.round(1 / n));
return lcm(...values);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment