Last active
July 20, 2021 22:14
-
-
Save nite/7711d69fb5f755239a44fd3232355adf to your computer and use it in GitHub Desktop.
Revisions
-
nite revised this gist
Jul 20, 2021 . 1 changed file with 5 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,13 @@ function pivot(meltedData, pivotCols: string[], varName: string, valueName: string) { const groups = {}; for (const d of meltedData) { const key = pivotCols.map((k) => d[k]).join('|'); const group = groups[key]; groups[key] = { ...(group ? group : fromPairs(pivotCols.map((k) => [k, d[k]]))), [d[varName]]: d[valueName], }; } return Object.values(groups); -
nite created this gist
Jul 20, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ function pivot(meltedData, columns: string[], varName: string, valueName: string) { const groups = {}; for (const d of meltedData) { const key = columns.map((k) => d[k]).join('|'); const group = groups[key]; groups[key] = Object.assign(group ? group : fromPairs(columns.map((k) => [k, d[k]])), { [d[varName]]: d[valueName], }); } return Object.values(groups); }