Created
June 25, 2018 22:24
-
-
Save jordan-enev/4e63529a4144629b01d2197784f0b4a0 to your computer and use it in GitHub Desktop.
Facade - utilities for building headings & rows
This file contains 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 characters
const buildHeadings = data => { | |
const headings = data.reduce((accumulator, item) => [...accumulator, ...Object.keys(item)], []) | |
return [...new Set(headings)] | |
} | |
const buildRows = (data, headings) => { | |
let rows = [] | |
data.forEach(item => { | |
let row = [] | |
headings.forEach(heading => { | |
row.push(item[heading]) | |
}) | |
rows.push(row) | |
}) | |
return rows | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment