Created
May 25, 2017 16:59
-
-
Save Sara3/38efd3d29e1b02dfd7fc43c5a9c517e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var f = function(n) { | |
var f = 1; | |
for (var i = 1; i <= n; i ++) { | |
f = f*i; | |
} | |
return f; | |
} | |
console.log(f(4)) | |
var generate = function(numRows) { | |
// numbers of rows create pascal tiangle | |
//pascal triangles that in each row both sides are the same | |
// generate n rows | |
//each row increase 1 by length | |
//increase input until half and then decrease it | |
//create container array | |
//n!/(r!*(n-r)!) | |
var container = []; | |
// for each n | |
for(var i = 1; i<= numRows; i++ ) { | |
var row = new Array(i); | |
for(var j = 0; j<row.length; j++) { | |
row[j] = (f(i))/(f(j)*(f(i-j))); | |
} | |
console.log(row); | |
container.push(row); | |
} | |
//create a row array with i len | |
//return container; | |
}; | |
console.log(generate(5)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment