Created
March 10, 2015 15:47
-
-
Save nobleach/0ceab87d87206cb6e871 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 generateWantedData(columnNames, ...data) { | |
// map over data, zipObject for each column name | |
return data.map(function(valueArray) { | |
return zipObject(columnNames, valueArray); | |
}); | |
} | |
console.log(generateWantedData(data[0], data.slice(1, data.length))); | |
// var wantedData = [{'B1':1,'B2':2,'B3':3},{'B1':4,'B2':5,'B3':6}, {'B1':7,'B2':8,'B3':9}]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment