Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
251 changes: 251 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 18 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,22 @@
*/

const pascalTriangle = (lineNumber) => {

}
const pascalTrianglePerLine = []; // Its like a multidimensional array (but really not, is just an array of arrays), saves line per line the pascal triangle to return later que specific line

module.exports = pascalTriangle;
for (let i = 0; i <= lineNumber; i++) {
let newLine = [];
for (let j = 0; j <= i; j++) {
if (j === 0 || j === i) { // The first and last time at the second cicle need have a 1 becaues thats the border of the triangle
newLine.push(1);
} else {
newLine.push(
pascalTrianglePerLine[i - 1][j - 1] + pascalTrianglePerLine[i - 1][j] // If is not the first line, need to take the top left and top right numbers and add them
);
}
}
pascalTrianglePerLine.push(newLine);
}
return pascalTrianglePerLine[lineNumber];
};

module.exports = pascalTriangle;