Skip to content

Instantly share code, notes, and snippets.

@jordan-enev
Created June 25, 2018 22:24
Show Gist options
  • Save jordan-enev/4e63529a4144629b01d2197784f0b4a0 to your computer and use it in GitHub Desktop.
Save jordan-enev/4e63529a4144629b01d2197784f0b4a0 to your computer and use it in GitHub Desktop.
Facade - utilities for building headings & rows
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