Recreate map, filter, and reduce as myMap, myFilter, myReduce
JavaScript arrays come with a set of powerful built-in methods like map(), filter(), and reduce() that are essential for manipulating array elements. The task is to recreate these methods, named myMap(), myFilter(), and myReduce(), by adding them to the Array.prototype. These custom methods should mimic the functionality of their native counterparts, enabling similar operations on arrays without using the built-in methods. MDN’s Array reference documents the native behavior of each method.
Here is a brief overview of what each method should accomplish:
initialValue if provided.These custom methods are not only a great way to understand how JavaScript’s built-in array methods work under the hood but also serve as an excellent exercise in enhancing one’s ability to extend native JavaScript objects in a meaningful way.