typescript-algorithms-and-datastructures
Version:
Useful algorithms and Data structures written in typescript.
40 lines • 1.25 kB
JavaScript
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function greatestCommonDivisor(a, b) {
if (!Number.isInteger(a) || !Number.isInteger(b)) {
return NaN;
}
if (a === 0 && b === 0) {
return NaN;
}
if (a < 0) {
a = Math.abs(a);
}
if (b < 0) {
b = Math.abs(b);
}
if (a === b) {
return a;
}
else if (a < b) {
return greatestCommonDivisorInternal(b, a);
}
else {
return greatestCommonDivisorInternal(a, b);
}
}
exports.greatestCommonDivisor = greatestCommonDivisor;
function greatestCommonDivisorInternal(a, b) {
return b > 0 ? greatestCommonDivisor(b, a % b) : a;
}
});
//# sourceMappingURL=greatestCommonDivisor.js.map