2 karma · joined Jun 24, 2014 (12y ago) · 1 submissions
comment 12y ago · link · parent
I wrote quite a fast "map" (along with the others) that looked a bit like:
exports.map = function fastMap (subject, fn, thisContext) {
var i = subject.length,
result = new Array(i);
if (thisContext) {
while (i--) {
result[i] = fn.call(thisContext, subject[i], i, subject);
}
} else {
while (i--) {
result[i] = fn(subject[i], i, subject);
}
}
return result;
};
I'm not sure if I just used "result = []", but on modern browsers I think that'd be recommended. But yeah, if you're programming for a web browser then using another impl of map is probably going to be a waste of time.