MCPcopy Create free account
hub / github.com/TodePond/ScreenPond / gcd

Function gcd

libraries/habitat-embed.js:667–680  ·  view source on GitHub ↗
(...numbers)

Source from the content-addressed store, hash-verified

665//======//
666{
667 const gcd = (...numbers) => {
668 const [head, ...tail] = numbers;
669 if (numbers.length === 1) return head;
670 if (numbers.length > 2) return gcd(head, gcd(...tail));
671
672 let [a, b] = [head, ...tail];
673
674 while (true) {
675 if (b === 0) return a;
676 a = a % b;
677 if (a === 0) return b;
678 b = b % a;
679 }
680 };
681
682 const reduce = (...numbers) => {
683 const divisor = gcd(...numbers);

Callers 1

reduceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected