logo
Search
showing results for - "javascript reduce fraction"
Perrine
14 Sep 2019
1// Reduce a fraction by finding the Greatest Common Divisor and dividing by it.
2function reduce(numerator,denominator){
3  var gcd = function gcd(a,b){
4    return b ? gcd(b, a%b) : a;
5  };
6  gcd = gcd(numerator,denominator);
7  return [numerator/gcd, denominator/gcd];
8}
9
10reduce(2,4);
11// [1,2]
12
13reduce(13427,3413358);
14// [463,117702]
15
source
similar questions
javascript round to 8 decimal placesangularjs fractionsize with dotjs round to nearest thousandredondear decimales javascriptjavascript divide return integer with 2 decimal placesreduce decimals to 4 digits javascriptrounding up a number so that it is divisible by 5 javascriptjavascript array of cumulative sumproper to mixed fraction in javascripttrailing zeros in factorial jsjavascript multiply a square matrixjs round up decimalround decimal jsjavascript truncate decimal without roundinghow to convert minus to plus jsjs convert to fractionjavascript convert minus to plusjavascript 2 decimal float array elementsjavascript decimal factorial
queries leading to this page
calculate fractions sum javascriptjavascript reduce fractionmath js reduce fractionjs reduce fractionjavascript reduce fraction
privacy policyterms of useinstagram
Crafted with  ♥  for everyone

sign in to continue
your answer for
you will get a confirmation link on this - you will have to click that for successful submission of your answer. we require this to keep the website free of spam, bots and unhelpful content
please ensure to add code which is syntactically corrent and executes properly
sign in to continue
ask question on maxinterview
you will get a confirmation link on this - you will have to click that for successful submission of your question. we require this to keep the website free of spam, bots and unhelpful content
please be clear, to the point and respectful
sign in to continue