Skip to content

Instantly share code, notes, and snippets.

@timkg
Created March 24, 2015 04:07
Show Gist options
  • Save timkg/309a6d12741638c486be to your computer and use it in GitHub Desktop.
Save timkg/309a6d12741638c486be to your computer and use it in GitHub Desktop.
Map-Reduce a collection of values into a list
[1, 2, 3]
.map(function (num) {
var listItem = document.createElement('li');
listItem.textContent = num;
return listItem;
})
.reduce(function (acc, cur) {
acc.appendChild(cur);
return acc;
}, document.createElement('ul'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment