From f4bb32575d0cc6b4015cb6aa7a31957907062c12 Mon Sep 17 00:00:00 2001 From: Omar Date: Wed, 5 Aug 2020 13:09:18 -0500 Subject: [PATCH] Done --- src/index.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index d25ae68..0bcdd62 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,20 @@ function diamond(size) { - // your code - return; + + if (size <= 0 || size % 2 === 0) return null; + + const repeater = chain => size => chain.repeat(size) + const rowSpace = repeater(' ') + const rowStar = repeater('*') + + let shape = '' + for (let row = 1; row <= size; row++) { +//The Math.abs () function returns the absolute value of a number + const spaces = Math.abs(size - ((2*row) - 1)) + const stars = size - spaces + shape += `${rowSpace(spaces / 2)}${rowStar(stars)}\n` + } + + return shape } module.exports = { diamond };