That's not an outlandish requirement; imagine that the callback can be expensive, and we would like to be able to adjust a centralized "map" function later so it farms things out to different processes/workers/etc.
To solve this for map_first_innermost, you'd have to throw an exception with the nested array, but this is just getting hideously ugly.
function map_first_innermost(arr, callback) {
try {
return map(arr, function(v) {
if (v instanceof Array) throw {itWasNested: v};
return callback(v);
});
} catch (e) {
if (e.itWasNested) {
return map_first_innermost(e.itWasNested, callback);
}
throw e;
}
}