Skip to content

Instantly share code, notes, and snippets.

@Fraasi
Created April 30, 2018 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fraasi/bd47a51ec101351469d6020059c53a73 to your computer and use it in GitHub Desktop.
Save Fraasi/bd47a51ec101351469d6020059c53a73 to your computer and use it in GitHub Desktop.
reOrganizeQuotes from { quote: author} to { author: [quote] }
function reOrganizeQuotes(quotes) {
// from { quote: author}
// to { author: [quote] }
const newObj = {}
Object.entries(quotes).forEach(([key, value]) => {
newObj[value] === undefined ?
newObj[value] = [key] :
newObj[value].push(key)
});
newObj.numberOfQuotes = Object.keys(newObj).reduce((acc, key) => {
return acc + newObj[key].length
}, 0)
newObj.numberOfauthors = Object.keys(newObj).length
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment