Skip to content

Commit

Permalink
Add test cases for gcdOfArray
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitanwar committed Dec 20, 2017
1 parent d624fe5 commit 1b3a70f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions snippets/gcdOfArray.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ It finds the GCD of all the numbers in an array by using `array.reduce` and the
const gcdOfArray = arr =>
{
const gcd = (x, y) => !y ? x : gcd(y, x % y);
arr.reduce((a,b) => gcd(a,b))
return arr.reduce((a,b) => gcd(a,b))
}
// functionName(sampleInput) -> sampleOutput
// gcdOfArray([1,2,3,4,5]) -> 1
// gcdOfArray([4,8,12]) -> 4
```

0 comments on commit 1b3a70f

Please sign in to comment.