From f64389f595198a3f109f40b0ca0f65760943ca62 Mon Sep 17 00:00:00 2001 From: jonathanrchamorro <68171390+jonathanrchamorro@users.noreply.github.com> Date: Mon, 14 Sep 2020 15:40:57 -0500 Subject: [PATCH] Reto resuelt --- src/index.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index d25ae68..1283e82 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,31 @@ function diamond(size) { // your code - return; + //Solucion + if (size <= 1 || size % 2 === 0) return null; + let printLn = (size, dots) => { + let spaces = (size - dots) / 2; + let strSpaces = " ".repeat(spaces); + let strDots = "*".repeat(dots); + return `${strSpaces}${strDots}\n`; + }; + let str = ""; + let n = 0; + // Parte de arriba del diamante + while (n < size) { + if (n % 2 != 0) { + str += printLn(size, n); + } + ++n; + } + //parte de abajo del diamante + n = size; + while (n > 0) { + if (n % 2 != 0) { + str += printLn(size, n); + } + --n; + } + return str; } module.exports = { diamond };