From 3ba58335b1f7e52865aadb5c48fc85a7f93de93e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Andrea?= Date: Tue, 28 Jul 2020 22:35:16 -0500 Subject: [PATCH] pascal triangle algorithm --- src/index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index f12ab1b..002be7d 100644 --- a/src/index.js +++ b/src/index.js @@ -4,7 +4,16 @@ */ const pascalTriangle = (lineNumber) => { - + const matrixPascal = [[1]]; + for (let j = 0; j < lineNumber; j++) { + const tempLine = [1]; + for (let i = 1; i < matrixPascal[j].length; i++) { + tempLine.push(matrixPascal[j][i-1]+matrixPascal[j][i]) + } + tempLine.push(1); + matrixPascal.push(tempLine); + } + return matrixPascal[lineNumber]; } module.exports = pascalTriangle; \ No newline at end of file