Last active
August 29, 2015 14:16
-
-
Save nobleach/c2b90db4c04f70df0427 to your computer and use it in GitHub Desktop.
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
var data = [['B1','B2','B3'],[1,2,3],[4,5,6],[7,8,9]]; | |
// this would normally be provided by some sort of functional lib (or in a real functional language) | |
function zipObject(keys, vals) { | |
var zip = {}; | |
keys.forEach(function(k,i) {zip[k] = vals[i];}); | |
return zip; | |
} | |
function car(arr) { | |
return arr[0]; | |
} | |
function cdr(arr) { | |
return arr.slice(1, arr.length); | |
} | |
function generateWantedData(columnNames, data) { | |
// map over data, zipObject for each column name | |
console.log(data); | |
return data.map(function(val) { | |
return zipObject(columnNames, val); | |
}); | |
} | |
console.log(generateWantedData(car(data), cdr(data))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment