UNPKG
mathball
Version:
latest (0.4.0)
0.4.0
0.3.1
0.3.0
0.2.0
0.1.2
0.1.1
0.1.0
A JavaScript library for Competitive Programming
github.com/pbiswas101/Mathball
pbiswas101/Mathball
mathball
/
lib
/
gcd
/
index.js
16 lines
(12 loc)
•
295 B
JavaScript
View Raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
'use strict'
;
/* Function: gcd() */
var
validate =
require
(
'../validation/integer-array'
);
function
gcd
(
a, b
) {
return
a ==
0
? b :
gcd
(b % a, a); }
module
.
exports
=
function
(
arr
) {
validate
(arr,
'gcd'
);
return
arr.
reduce
(
function
(
prev, next
) {
return
gcd
(prev, next); }, arr[
0
]); };