← Back to challenges

Find Greatest Common Divisor of N Numbers

JavaScriptHardnumbersarraysmath

Instructions

Create a function that takes an array of numbers and returns the greatest common factor of those numbers.

Examples

gcd([84, 70, 42, 56]) ➞ 14

gcd([19, 38, 76, 133]) ➞ 19

gcd([120, 300, 95, 425, 625]) ➞ 5

Notes

The GCD is the largest factor that divides all numbers in the array.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.