collect unique and sum

This commit is contained in:
TreetopFlyer 2021-05-08 09:56:44 -04:00 committed by TreetopFlyer
parent f938bbaa2e
commit a127d702a3

View File

@ -71,6 +71,40 @@ var N = {
}
};
</script>
<script>
var rows = [
["a", 1],
["b", 2],
["a", 3],
["b", 1],
["a", 0],
["b", 7],
];
Uniques = (inRows, inColumnIndex, inSumIndicies) =>
{
let uniques = {};
inRows.forEach((inRow)=>
{
let value = inRow[inColumnIndex];
let match = uniques[value];
if(!match)
{
match = uniques[value] = {Sum:[...inRow], Rows:[]};
}
else
{
inSumIndicies.forEach(inIndex => match.Sum[inIndex] += inRow[inIndex]);
}
match.Rows.push(inRow);
});
return uniques;
};
console.log(Uniques(rows, 0, [1]));
</script>
<script>
let tree1 = N.Create("root1",
N.Create("branch1",