I am looking for a function that can produce the nth line of Pascal's triangle. I've found several solutions online but I don't quite fully understand them. Could someone explain this code block? I don't understand why unshift method wouldn't just produce an array of 1s.
const getRow = rowIndex => {
const res = []
while (res.length <= rowIndex) {
res.unshift(1)
for(let i = 1; i < res.length - 1; i++) {
res[i] += res[i + 1]
}
}
return res
}