Pascal's Triangle

Change the depth to the desired amount below

Minimum is 1 and maximum is 17

The Code

This is an example of pascal's triangle done iteratively

function pascal(depth) {
	clearTriangleText('');
	if (typeof(parseInt(depth)) != 'number') { return; }
	if (depth <= 0) { return; }		
	var a = [];
	for (i=0;i<depth;i++) {
		if (i>0) {
			a[i] = [];
			for(j=0;j<a[i-1].length + 1;j++) {
				var p0 = (a[i-1][j])?a[i-1][j]:1;
				var p1 = (a[i-1][j+1])?a[i-1][j+1]:0;
				p0 = parseInt(p0);
				p1 = parseInt(p1);
				var p = p0 + p1;
				a[i].push([p]); 
			}
			a[i].unshift(a[i].pop());
		}else{
			a[i] = [1];
		}
		setTriangleText(a[i]);
		if (i>15) {
			setTriangleText('Let\'s just stop \
			  it there for browser sake');
			break;
		}
	}
}

This is an example of pascal's triangle done recursively

function pascal_r(depth, current, _array) {
  if ((typeof(parseInt(depth)) != 'number') ||
      (typeof(parseInt(current)) != 'number') ||
      (depth <= 0) ||
      (current >= depth)) { return; }
  
  var a = (_array instanceof Array)?_array:[];
  var i = (current)?current:0;
  
  if (i>0) {
    a[i] = [];
    for(j=0;j<a[i-1].length + 1;j++) {
      var p0 = parseInt((a[i-1][j])?a[i-1][j]:1);
      var p1 = parseInt((a[i-1][j+1])?a[i-1][j+1]:0);
      a[i].push([(p0 + p1)]); 
    }
    a[i].unshift(a[i].pop());
  }else{
    clearTriangleText('');
    a[i] = [1];
  }
  
  setTriangleText(a[i]);
  
  if (i>15) {
    setTriangleText('Let\'s just stop it there for browser sake');
  }else{
    arguments.callee(depth, (i+1), a);
  }
}