Created
April 30, 2018 19:37
-
-
Save Fraasi/bd47a51ec101351469d6020059c53a73 to your computer and use it in GitHub Desktop.
reOrganizeQuotes from { quote: author} to { author: [quote] }
This file contains 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
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