Code I Ran Today: 08/16/2017
See It Live and Run It Yourself: Code I Ran Today: 08/16/2017
Skills Used: for loop, array, function, object, array of arrays to array of objects
Background: Took me 3 hours! I had some else’s answer available, but did not want to cheat. I FORCED myself to get this one. I think I even started hallucinating a bit...but I told myself not to quit and to get it. And I did.
Code:
function transformEmployeeData(employeeData) {
var array = []; for (var i = 0; i < employeeData.length; i++) { var obj= {}; for(var j = 0; j < employeeData[0].length; j++) {
obj[employeeData[i][j][0]] = employeeData[i][j][1];
} array.push(obj); }
return array;
}
transformEmployeeData([ [ ['firstName1', 'Joe'], ['lastName1', 'Blow'], ['age1', 42], ['role1', 'clerk'] ], [ ['firstName2', 'Mary'], ['lastName2', 'Jenkins'], ['age2', 36], ['role2', 'manager'] ] ]);














