Created
September 21, 2014 21:16
-
-
Save imbcmdth/eb55b78ee4f5b594bca2 to your computer and use it in GitHub Desktop.
2D array to table
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
function appender (to, el) { to.appendChild(el); return to; } | |
function genElement (type, next) { | |
return next(document.createElement(type)) | |
} | |
var genTextNode = document.createTextNode.bind(document); | |
function genElements (values, generator, parent) { | |
return values.map(generator) | |
.reduce(appender, parent); | |
} | |
function genTable (values) { | |
return genElement('table', genElements.bind(null, values, genRow)); | |
} | |
function genRow (values) { | |
return genElement('tr', genElements.bind(null, values, genCell)); | |
} | |
function genCell (value) { | |
return genElement('td', genElements.bind(null, [value], genTextNode)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment