mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2025-12-08 19:06:00 +00:00
* Get Bit: Make more terse * Power of two: Allowed 1 as a valid power of 2. Power of two: Removed unnecessary exception throwing. * Fisher Yates: Made more terse * Least Common Multiple: Fill undefined value * Greatest Common Divisor: Fill undefined value. Greatest Common Divisor: Make more terse.
12 lines
277 B
JavaScript
12 lines
277 B
JavaScript
/**
|
|
* @param {number} originalA
|
|
* @param {number} originalB
|
|
* @return {number}
|
|
*/
|
|
export default function euclideanAlgorithm(originalA, originalB) {
|
|
const a = Math.abs(originalA);
|
|
const b = Math.abs(originalB);
|
|
|
|
return (b === 0) ? a : euclideanAlgorithm(b, a % b);
|
|
}
|