Skip to content

Instantly share code, notes, and snippets.

@Angelfire
Created January 11, 2023 02:29
Show Gist options
  • Save Angelfire/61349a368022171cfb0fb226ffd37850 to your computer and use it in GitHub Desktop.
Save Angelfire/61349a368022171cfb0fb226ffd37850 to your computer and use it in GitHub Desktop.
Callback functions
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;
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