Skip to content

Instantly share code, notes, and snippets.

@soney
Created October 24, 2011 16:04
Show Gist options
  • Save soney/1309386 to your computer and use it in GitHub Desktop.
Save soney/1309386 to your computer and use it in GitHub Desktop.
A function that, given an array and a mapping function that uses a callback, calls a callback with the mapped array as a parameter
var callback_map = function(arr, func, callback) {
var rv = [];
var waiting_for = arr.length;
arr.forEach(function(item, index) {
func(item, function(mapped) {
rv[index] = mapped;
waiting_for--;
if(waiting_for <= 0) {
callback(rv);
}
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment