GCD Command

This commit is contained in:
Dragon Fire
2021-05-02 21:18:27 -04:00
parent ccebe89c2a
commit ef06abf451
4 changed files with 54 additions and 21 deletions
+14
View File
@@ -111,6 +111,20 @@ module.exports = class Util {
return crypto.createHash(algorithm).update(text).digest('hex');
}
static gcd(a, b) {
if (b > a) {
const temp = a;
a = b;
b = temp;
}
while (b !== 0) {
const m = a % b;
a = b;
b = m;
}
return a;
}
static streamToArray(stream) {
if (!stream.readable) return Promise.resolve([]);
return new Promise((resolve, reject) => {