100 points · by johndcook · 13y ago · 31 comments
Thanks for the new book fogus, love TJoC 1 and am eagerly awaiting the sequel.
http://swannodette.github.io/mori/
Just to avoid confusion: mori the library, as distributed by npm, is already compiled. Building the library itself requires a compile step, but an end-user just needs to load it with a script tag or require("mori").
Well, at least one mutating index is convenient:
function forEach (a,f) {
for(var i=0;i<a.length;i++) f(a[i],i,a);
}
After that, you generally wouldn't need more indexes.But does it really require a mutating index?
function forEach (a,f,i) {
var n = i || 0;
f(a[0],n,a);
if(a.length > 1)
forEach(a.slice(1),f,n+1);
}
Array copies aren't particularly efficient, of course, and there are languages with data structures backing arrays for which some similar approach might be efficient, but there it is.