Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
16
Task/Pascals-triangle/JavaScript/pascals-triangle-6.js
Normal file
16
Task/Pascals-triangle/JavaScript/pascals-triangle-6.js
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
const aux = (() => {
|
||||
const layers = [[1], [1]]
|
||||
return n => {
|
||||
if(layers[n]) return layers[n]
|
||||
const prevLayer = aux(n - 1)
|
||||
const shifted = [0, ...prevLayer]
|
||||
layers[n] = shifted.map((x, i) => (prevLayer[i] || 0) + x)
|
||||
return layers[n]
|
||||
}
|
||||
})()
|
||||
const pascal = n => {
|
||||
for(let i = 1; i <= n; i++) {
|
||||
console.log(aux(i).join(' '))
|
||||
}
|
||||
}
|
||||
pascal(8)
|
||||
Loading…
Add table
Add a link
Reference in a new issue