Skip to main content
2 of 6
added 676 characters in body

I prefer use input output:

var func = (n) => Array.from(Array(n).keys()).reverse()
function staircase(n) {
    var fun = func(n).map((value, index, arr)=>{
        return console.log(' '.repeat(value)+'#'.repeat(index+1)+'\n')
    })
    return fun
}

staircase(10)

func is a output of a logic: Array.from(Array(n).keys()).reverse() that receives n:integer parameter.

Array.from is a new syntax from ES6, it means that you can fill an array from "here" to "there" ie: Array.from(0, 6) returns [0,1,2,3,4,5,6]

so all the staircase(n) return is a output of map of this array. Such array that receive Array(n).keys() and reverses it with prototype reverse()

so that the array could be: [6,5,4,3,2,1,0] instead.

the map repeat iterate over the array created from Array.from(Array(n).keys()).reverse() and return a log for each item such as every item repeats ' ' (blank space) + "#" at the end of this string.