the index variable below is incorrectly initialized because f() will be returning stuff other than numbers, like strings. So what’s the worst that can happen here? My testing seems to indicate that it has no effect, but now I am wondering…
function index(o, f) {
var index = []; // should be index = {};
each(o, function(k, v, o) { index[f(k, v, o)] = v; });
return index;
}
Javascript arrays are special objects that have an automatically set
lengthproperty and inheritArray.prototype.Unless you use a
lengthproperty, there is no harm in treating an array as an object.