Created
October 2, 2017 23:58
-
-
Save ryan-hamblin/e7add2b5eb7c2093418eab6612410ba4 to your computer and use it in GitHub Desktop.
for loops with ryan
This file contains 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
const arrayOfStrings = ['Hello', 'Hola', 'Oi', 'Neehow', 'Guten Tag']; | |
const arrayOfInts = [1, 2, 3, 4, 5]; | |
const ln = arrayOfStrings.length; | |
console.log(ln); | |
console.log(arrayOfStrings[1]); | |
for (let i = 0; i < ln; i++) { | |
console.log(arrayOfStrings[i], i); | |
} | |
const each = (someArray, someCallBack) => { | |
for (let i = 0; i < someArray.length; i++) { | |
someCallBack(someArray[i], i); | |
} | |
}; | |
const reusableFunction = (element, index) => { | |
console.log(`The element ${element} is at index ${index}`); | |
}; | |
each(arrayOfStrings, reusableFunction); | |
each(arrayOfInts, reusableFunction); | |
arrayOfInts.forEach(reusableFunction); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment