I am trying to make Pascal's Triangle in JavaScript but there are lots of errors. I have know idea why errors are happening but there are some.
Code:
function triangle() {
this.rows = [[1]];
this.genRow = function() {
this.rows.push([]);
this.rows[this.rows.length-1].push(1);
for (var i = 0; i < this.rows[this.rows.length-1].length; i++){
var u = [this.rows[this.rows.length-1][i-1], this.rows[this.rows.length-1][i], this.rows[this.rows.length-1][i+1]];
var f = function(e) {
return e != undefined;
};
function s() {
var sum=0;
for (var index = 0; i < this.legnth; i++){
sum =+ this[i];
}
return sum;
}
u = u.filter(f).s();
this.rows[this.rows.length-1].push(u);
}
this.rows[this.rows.length-1].push(1);
}
}
var t = new triangle();
t.genRow();
console.log(t.rows);
Thanks.