Skip to content

Instantly share code, notes, and snippets.

@terkel
Last active March 4, 2019 06:42
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 terkel/6ec73cee2f425e9ca15376916e231ad0 to your computer and use it in GitHub Desktop.
Save terkel/6ec73cee2f425e9ca15376916e231ad0 to your computer and use it in GitHub Desktop.
// Reduce a fraction
// @param {Number} $a
// @param {Number} $b
// @returns {Array} - A reduced fraction
@function frac-reduce ($a, $b) {
$gcd: gcd($a, $b);
@return $a / $gcd, $b / $gcd;
}
// Find the greatest common divisor
// @param {Number} $a
// @param {Number} $b
// @returns {Number} - The greatest common divisor
@function gcd ($a, $b) {
@return if($b == 0, $a, gcd($b, $a % $b));
}
// Find the least common multiple
// @param {Number} $a
// @param {Number} $b
// @returns {Number} - The least common multiple
@function lcm ($a, $b) {
@return $a * $b / gcd($a, $b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment