Skip to content

Instantly share code, notes, and snippets.

@Calvein
Created April 30, 2013 04:43
Show Gist options
  • Save Calvein/5486620 to your computer and use it in GitHub Desktop.
Save Calvein/5486620 to your computer and use it in GitHub Desktop.
Invert array/object data
headings = []
_.each o.groups, (group, label) =>
headings.push(label)
groups = {}
_.each o.headings, (heading) =>
groups[heading] = values: []
_.each headings, (heading, i) =>
_.each o.groups[Object.keys(o.groups)[i]].values, (val, j) =>
groups[Object.keys(groups)[j]].values.push(val)
o.headings = headings
o.groups = groups
copy JSON.stringify o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment