Created
May 24, 2017 15:12
-
-
Save rosshadden/1963312ad12863263c24d26689e4e33f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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