Last active
January 17, 2023 13:53
-
-
Save imkrish/5201935bdb71c47f295549a48ab907c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function arrow(number) { | |
const isEven = number % 2 == 0; | |
const middles = isEven ? [Math.floor(number / 2) - 1, Math.floor(number / 2)] : [Math.floor(number / 2)] | |
const middle = middles[0] | |
new Array(number).fill(1).forEach((_, idx) => { | |
let indent = 0; | |
if (middles.includes(idx)) { | |
indent = middle | |
} else if (idx < middle) { | |
indent = idx | |
} else { | |
indent = number - 1 - idx | |
} | |
console.log(`${' '.repeat(indent)}*`) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment