Last active
April 13, 2020 04:01
-
-
Save vinicius5581/c1d1876a4f6156a3d05059ca4fd5948b to your computer and use it in GitHub Desktop.
Array.prototype
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 numbersArray = [1, 2, 3, 4]; | |
const logTimesTwo = num => console.log(num * 2); | |
const customForEach = (arr, cb) => { | |
for (let i = 0; i < arr.length; i++) { | |
cb(arr[i]); | |
} | |
} | |
customForEach(numbersArray, logTimesTwo); |
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
// custom forEach without callback | |
const numbersArray = [1, 2, 3, 4]; | |
const logTimesTwo = num => console.log(num * 2); | |
const customForEach = (arr) => { | |
for (let i = 0; i < arr.length; i++) { | |
logTimesTwo(arr[i]); | |
} | |
} | |
customForEach(numbersArray); |
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 numbersArray = [1, 2, 3, 4]; | |
console.log(numbersArray[0]); // 1 | |
console.log(numbersArray[1]); // 2 | |
console.log(numbersArray[2]); // 3 | |
console.log(numbersArray[3]); // 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment