collect unique and sum
This commit is contained in:
parent
f938bbaa2e
commit
a127d702a3
34
index.html
34
index.html
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user