Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to get greatest common divisor in javascript

function gcd_two_numbers(x, y) {
  if ((typeof x !== 'number') || (typeof y !== 'number')) 
    return false;
  x = Math.abs(x);
  y = Math.abs(y);
  while(y) {
    var t = y;
    y = x % y;
    x = t;
  }
  return x;
}

console.log(gcd_two_numbers(12, 13));
console.log(gcd_two_numbers(9, 3));
Comment

PREVIOUS NEXT
Code Example
Javascript :: angular input date binding on variable update 
Javascript :: linebreak-style eslint 
Javascript :: javascript iterate over object 
Javascript :: get cuurent route name nextjs 
Javascript :: log arguments in javascript 
Javascript :: javascript has string 
Javascript :: react how to scroll to element 
Javascript :: codewars js Get the Middle Character 
Javascript :: javascript select option value onchange 
Javascript :: postman check for null or undefined 
Javascript :: nextjs websocket.js?a9be:46 WebSocket connection to 
Javascript :: vs code prevent auto grml closing in js files 
Javascript :: sendgrid bulk hide each other on the email 
Javascript :: express get request origin 
Javascript :: xmlhttprequest post form 
Javascript :: find array object value is already in use 
Javascript :: get text of selected option in select2 jquery 
Javascript :: loopback order by limit 
Javascript :: load js after ajax 
Javascript :: casperjs exit 
Javascript :: matomo error tracking 
Javascript :: var socket = io(); reconnect 
Javascript :: node js get files in dir 
Javascript :: js arrays check if there is intersection 
Javascript :: jquery get all file input elements 
Javascript :: router class in backbone 
Javascript :: javascript get diagonals of array 
Javascript :: js escape ampersand 
Javascript :: how to get id from url in javascript 
Javascript :: fs node delete folder 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =