iterators started

This commit is contained in:
unknown 2019-09-07 13:05:47 -04:00
parent 9e2012192d
commit fd835a4d87
2 changed files with 46 additions and 10 deletions

View File

@ -1,16 +1,19 @@
import {Table} from './table.ts'; import {Table} from './table.ts';
var table;
var leaves;
var rows;
var rows = [ rows = [
["a","1"], ["a","1"],
["b","2"], ["b","2"],
["a","3"], ["a","3"],
["b","1"], ["b","1"],
["a","2"], ["a","2"],
["b","3"], ["b","3"],
] ];
var t; table = new Table("Root", rows);
t = new Table("Root", rows); table.PivotTree([0, 1]);
t.PivotTree([0, 1]); table.ItrLeaves( inLeaf => console.log(inLeaf) );
console.log(t); console.log(table, leaves);

View File

@ -1,3 +1,17 @@
export class Sum
{
ColumnIndex: number;
Original: number;
FromParents: number;
FromChildren: number;
FromOutside: number;
constructor()
{
this.ColumnIndex = 0;
}
}
export class Table export class Table
{ {
Name: string; Name: string;
@ -20,10 +34,10 @@ export class Table
var context: Table; var context: Table;
context = this; context = this;
this.Rows.forEach((inRow)=> this.Rows.forEach((inRow: Array<string>)=>
{ {
cell = inRow[inColumn]; cell = inRow[inColumn];
child = this.Children.find( inChild => inChild.Name == cell ); child = this.Children.find( (inChild: Table) => inChild.Name == cell );
if(!child) if(!child)
{ {
child = new Table(cell, []); child = new Table(cell, []);
@ -34,7 +48,6 @@ export class Table
}); });
this.Rows = []; this.Rows = [];
} }
PivotTree(inColumns: Array<number>) PivotTree(inColumns: Array<number>)
{ {
var columns: Array<number>; var columns: Array<number>;
@ -45,9 +58,29 @@ export class Table
} }
columns = [...inColumns]; columns = [...inColumns];
this.Pivot(columns.shift()); this.Pivot(columns.shift());
this.Children.forEach( (inChild) => this.Children.forEach( (inChild: Table) =>
{ {
inChild.PivotTree(columns); inChild.PivotTree(columns);
}); });
} }
ItrParents(inFunction: Function)
{
if(this.Parent)
{
inFunction(this.Parent);
this.Parent.ItrParents(inFunction);
}
}
ItrLeaves(inFunction:Function)
{
if(this.Children.length == 0)
{
inFunction(this);
}
else
{
this.Children.forEach( (inChild: Table) => inChild.ItrLeaves(inFunction) );
}
}
} }