This project contains custom implementations of important JavaScript array methods to understand how they work internally.
- myForEach()
- myMap()
- myFilter()
- myReduce()
The goal of this project is to strengthen core JavaScript fundamentals by recreating built-in array methods using basic loops and logic.
- Takes a callback function
- Executes the function for each element
- Returns undefined
- Takes a callback function
- Returns a new array
- Each element is transformed using the callback
- Takes a callback function
- Returns a new array
- Includes elements where callback returns true
- Takes a callback function and an optional initial value
- Returns a single accumulated value
const arr = [1, 2, 3, 4, 5];
const doubled = arr.myMap((num) => num * 2);
console.log(doubled);
const even = arr.myFilter((num) => num % 2 === 0);
console.log(even);
const sum = arr.myReduce((acc, curr) => acc + curr, 0);
console.log(sum);