Skip to content

Commit

Permalink
fixes duplication bug
Browse files Browse the repository at this point in the history
  • Loading branch information
xenatisch committed Dec 31, 2020
1 parent 3e7b2f0 commit 3264638
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions data/processor/csv/csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,11 @@ const flatten = ( doc: DBResponseItem ): any[] => {
const initialKeys = Object.keys(doc);


let nestedColumns: string[] = initialKeys.reduce((acc: string[], item: string, ind: number) => {
let nestedColumns: Set<string> = new Set(initialKeys.reduce((acc: string[], item: string, ind: number) => {
return Array.isArray(doc[initialKeys[ind]])
? [...acc, item]
: acc
}, []);


for ( let ind = 0; ind < initialKeys.length; ind++ ) {
if ( Array.isArray(doc[initialKeys[ind]]) )
nestedColumns.push(initialKeys[ind]);
}

}, []));

const baseColumns = [
"date",
Expand Down Expand Up @@ -80,7 +73,7 @@ const toCsv = (docs: GenericDBResponse, nestedMetrics: string[]) => {
? docs.map(flatten).reduce((acc, item) => [...acc, ...item], [])
: docs;

const result = Array(flattenedDocs.length).fill("");
const result = new Array(flattenedDocs.length).fill("");

const sampleIndex = flattenedDocs
.map((item, ind) => [Object.keys(item).length, ind])
Expand Down

0 comments on commit 3264638

Please sign in to comment.