I currently have this input:
[
[['firstName', 'Joe'], ['lastName', 'Blow'], ['age', 42], ['role', 'clerk']],
[['firstName', 'Mary'], ['lastName', 'Jenkins'], ['age', 36], ['role', 'manager']]
];
The output should be as follows:
[
{ firstName: 'Joe', lastName: 'Blow', age: 42, role: 'clerk' },
{ firstName: 'Mary', lastName: 'Jenkins', age: 36, role: 'manager' }
];
I wrote the following code:
function transformEmployeeData(array) {
let newArr = [];
for(var i = 0; i< array.length; i++) {
let newObj = {}
for(var j = 0; j< array[i].length; j++) {
newObj[array[i][j][0]] = array[i][j][1]
}
newArr.push(newObj);
}
return newArr;
}
However, I want to try and use the .map() and .reduce() functions. How can I implement them?