Skip to content

Instantly share code, notes, and snippets.

@JeffML
Created October 29, 2017 21:55
Show Gist options
  • Save JeffML/6a2a3493d625d1b04f40192891a406d6 to your computer and use it in GitHub Desktop.
Save JeffML/6a2a3493d625d1b04f40192891a406d6 to your computer and use it in GitHub Desktop.
handrolled rowset to JSON conversion
const handrolled = (rs) => {
const authors = {}
rs.forEach(r => {
const authname = [r.last_name, r.first_name].join(',');
if (!authors[authname]) {
authors[authname] = {
categories: {}
}
}
var author = authors[authname];
if (!author.categories[r.category]) {
author.categories[r.category] = {
titles: []
}
}
var category = author.categories[r.category]
if (!category.titles.includes(r.title)) {
category.titles.push(r.title)
}
})
return authors;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment