Created
January 11, 2023 02:29
-
-
Save Angelfire/61349a368022171cfb0fb226ffd37850 to your computer and use it in GitHub Desktop.
Callback functions
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
function forEach(arr, callback) { | |
// for each element in the arr, run the callback, passing in the element | |
for (let i = 0; i < arr.length; i++) { | |
callback(arr[i], i) | |
} | |
} | |
module.exports = forEach; |
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
function map(arr, callback) { | |
const newArr = [] | |
for(let i = 0; i < arr.length; i++) { | |
newArr.push(callback(arr[i])) | |
} | |
return newArr | |
} | |
module.exports = map; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment