From d74df3dc8fbb40bbee93aa14c5ed58dc5c120f69 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Fri, 29 Dec 2017 13:11:38 +0200 Subject: [PATCH] Update gcd.md --- snippets/gcd.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/snippets/gcd.md b/snippets/gcd.md index 251fc14ae..8c4011b4d 100644 --- a/snippets/gcd.md +++ b/snippets/gcd.md @@ -2,15 +2,15 @@ Calculates the greatest common divisor between two or more numbers/arrays. -The helperGcd function uses recursion. +The `helperGcd `function uses recursion. Base case is when `y` equals `0`. In this case, return `x`. Otherwise, return the GCD of `y` and the remainder of the division `x/y`. ```js -const gcm = (...arr) => { -let data = [].concat(...arr) -const helperGcd = (x, y) => (!y ? x : gcd(y, x % y)); -return data.reduce((a, b) => helperGcd(a, b)) +const gcd = (...arr) => { + let data = [].concat(...arr); + const helperGcd = (x, y) => (!y ? x : gcd(y, x % y)); + return data.reduce((a, b) => helperGcd(a, b)); } ```