Skip to content

Instantly share code, notes, and snippets.

@dominickp
Created July 8, 2016 20:09
Show Gist options
  • Save dominickp/1f1dfa457ea80cfec6fd8ed4ff3717c3 to your computer and use it in GitHub Desktop.
Save dominickp/1f1dfa457ea80cfec6fd8ed4ff3717c3 to your computer and use it in GitHub Desktop.
Switch forEach helper function
/*
Foreach helper function
callback
Function to execute for each element, taking three arguments:
currentValue
The current element being processed in the array.
index
The index of the current element being processed in the array.
array
The array that forEach() is being applied to.
*/
var forEach = function(array, callback){
var currentValue, index;
for (i = 0; i < array.length; i += 1) {
currentValue = array[i];
index = i;
callback(currentValue, i, array);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment