Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript reduce fraction

// Reduce a fraction by finding the Greatest Common Divisor and dividing by it.
function reduce(numerator,denominator){
  var gcd = function gcd(a,b){
    return b ? gcd(b, a%b) : a;
  };
  gcd = gcd(numerator,denominator);
  return [numerator/gcd, denominator/gcd];
}

reduce(2,4);
// [1,2]

reduce(13427,3413358);
// [463,117702]
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to avoid json decode problem in python 
Javascript :: javascript copy image to clipboard 
Javascript :: sublime node 
Javascript :: using bootstrap in react 
Javascript :: how to access parent function from iframe 
Javascript :: javascript dynamic import folder 
Javascript :: js number format 
Javascript :: sortby vue 
Javascript :: how to scroll smoothly in to the top in react js 
Javascript :: localstorage javascript array 
Javascript :: js select by data attribute 
Javascript :: javascript compare arrays 
Javascript :: create component with module and routing in angular 8 
Javascript :: find in array and change 
Javascript :: cannot get issue in nodejs 
Javascript :: How to lock Orientation for a particular screen in ios in react native 
Javascript :: isnan javascript 
Javascript :: stop submit form jquery 
Javascript :: how to make button disabled in jquery before send 
Javascript :: regex find string between two characters 
Javascript :: app.use 
Javascript :: js add html element to div 
Javascript :: js get form inputs 
Javascript :: javascript scroll to top 
Javascript :: onclick change image src javascript 
Javascript :: import modules js html 
Javascript :: javascript array move element one position 
Javascript :: start date and end date validation antd 
Javascript :: smooth scroll mouse wheel javascript 
Javascript :: create react native 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =