What is the fastest algorithm for getting from something like this:
var array = [ [1,\'a\'], [2,\'b\'], [3,\'c\'] ];
to something like this
You could indeed use Array.prototype.reduce:
function objectify(array) {
return array.reduce(function(p, c) {
p[c[0]] = c[1];
return p;
}, {});
}
where p is the result of the previous iteration, initially {}, and c is the current element of the array.
It's unlikely to be any faster than array.forEach, but it is IMHO cleaner. I don't believe there's any simpler implementation than this.
NB: a function to do exactly this already exists in the Underscore library: _.object(array)