Created
October 29, 2017 21:55
-
-
Save JeffML/6a2a3493d625d1b04f40192891a406d6 to your computer and use it in GitHub Desktop.
handrolled rowset to JSON conversion
This file contains hidden or 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 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