Skip to content

Instantly share code, notes, and snippets.

@sergi
Created April 4, 2012 14:49
Show Gist options
  • Save sergi/2302088 to your computer and use it in GitHub Desktop.
Save sergi/2302088 to your computer and use it in GitHub Desktop.
JavaScript reduce implementation
var __reduce= function (func, list, initial) {
if (initial != null) {
var value = initial;
var idx = 0;
} else if (list) {
var value = list[0];
var idx = 1;
} else {
return null;
}
for (; idx < list.length; idx++) {
value = func(value, list[idx]);
}
return value;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment