Created
December 5, 2017 11:44
-
-
Save nanoaquila/2d0a3002c46e384aa2f9f41539d17bb1 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 calculateOddsDecimal(a, b) { | |
return (a / b); | |
} | |
function calculateOddsPercent(a, b) { | |
return (calculateOddsDecimal(a, b) * 100).toFixed(2); | |
} | |
function fractionToDecimal(fraction) { | |
let fractional = fraction.split('/'); | |
return fractional[0] / fractional[1]; | |
} | |
function decimalToFraction(decimal) { | |
let gcds = gcd(decimal * 100, 100); | |
return `${((decimal * 100) / gcds)}/${(100 / gcds)}`; | |
} | |
function gcd(numerator, denominator) { | |
if (!denominator) { | |
return numerator; | |
} | |
return gcd(denominator, numerator % denominator); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment