Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
12
Task/Pascals-triangle/JavaScript/pascals-triangle-5.js
Normal file
12
Task/Pascals-triangle/JavaScript/pascals-triangle-5.js
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
const aux = n => {
|
||||
if(n <= 1) return [1]
|
||||
const prevLayer = aux(n - 1)
|
||||
const shifted = [0, ...prevLayer]
|
||||
return shifted.map((x, i) => (prevLayer[i] || 0) + x)
|
||||
}
|
||||
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