We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 99b8adc commit 33921a5Copy full SHA for 33921a5
src/games/gcd.js
@@ -5,16 +5,14 @@ import {
5
} from '../index.js';
6
7
const gcd = (a, b) => {
8
- if (a > b) {
9
- if (b === 0) {
10
- return a;
11
- } return gcd(b, a % b);
12
- }
13
- if (b > a) {
14
- if (a === 0) {
15
- return b;
16
- } return gcd(a, b % a);
17
- } return a;
+ if (a === b) {
+ return a;
+ } const maxDivisor = a > b ? b : a;
+ for (let divisor = maxDivisor; divisor > 1; divisor -= 1) {
+ if (a % divisor === 0 && b % divisor === 0) {
+ return divisor;
+ }
+ } return 1;
18
};
19
20
export default () => {
0 commit comments