Created
May 21, 2014 13:19
-
-
Save artcommacode/f9132accf1c491d2c3be to your computer and use it in GitHub Desktop.
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
// Which is more 'functional'? | |
//FIRST | |
render.allTags = pages.reduce(function (allTags, page) { | |
page.tags.split(', ').forEach(function (tag) { | |
allTags[tag] = ++allTags[tag] || 1; | |
}); | |
return allTags; | |
}, {}); | |
//SECOND | |
render.allTags = pages.reduce(function (allTags, page) { | |
return allTags.concat(page.tags.split(', ')); | |
}, []).reduce(function (countedTags, tag) { | |
countedTags[tag] = ++countedTags[tag] || 1; | |
return countedTags; | |
}, {}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment