Skip to content

Instantly share code, notes, and snippets.

@ryan-hamblin
Created October 2, 2017 23:58
Show Gist options
  • Save ryan-hamblin/e7add2b5eb7c2093418eab6612410ba4 to your computer and use it in GitHub Desktop.
Save ryan-hamblin/e7add2b5eb7c2093418eab6612410ba4 to your computer and use it in GitHub Desktop.
for loops with ryan
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