Trying to manipulate this:
input = [
[ ['a','b'], ['c','d'], ['e','f'] ],
[ ['g','h'], ['i','j'], ]
]
to
output = [
{a: 'b', c: 'd', e: 'f'},
{g: 'h', i: 'j'},
]
Here's what I have so far:
function transform(array) {
result = [];
for (var i=0; i<array.length; i++){
for (var j=0; j<array[i].length; j++){
// How can I create an object here?
object.array[i][j][0] = array[i][j][1];
}
}
return result;
}
I'm trying to solve this as a coding challenge so I don't necessarily want the answer but I'm unsure of how to proceed. Since the number of arrays that have a pair of strings inside is not uniform (for instance, first set of arrays within the input array has 3 sets, and the second set has 2 sets, I reckon I need to dynamically create objects within each loop that I can add to the results array at the end. How can I do this?
I don't think I'm supposed to use any sort of fancier / higher order functions. The goal is to build up my familiarity with the fundamentals.