Skip to content

Instantly share code, notes, and snippets.

@imkrish
Last active January 17, 2023 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imkrish/5201935bdb71c47f295549a48ab907c1 to your computer and use it in GitHub Desktop.
Save imkrish/5201935bdb71c47f295549a48ab907c1 to your computer and use it in GitHub Desktop.
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