Created
July 8, 2016 20:09
-
-
Save dominickp/1f1dfa457ea80cfec6fd8ed4ff3717c3 to your computer and use it in GitHub Desktop.
Switch forEach helper function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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