A polyfill is a code snippet (in terms of javascript web architecture) used for modern world functionalities on older browsers that do not implement it natively. They're essential because it teaches various deep-level concepts of javascript. Here, we are going to implement map, filter, reduce and promise.all polyfills.
User Stories:
myMap()
method that can iterate over an array and returns a copy of the array with the function that the user provides.myFilter()
method that can iterate over an array and returns a new array based on a boolean that matches the user function passed.myReduce()
method that takes in an array and returns one single value at the end, based on the function that the user provides. It also takes into account an accumulator.myPromise.all()
method that takes in an array of promises
and resolves ONLY if all of the passed promises resolve.Click to reveal
Try using the native this
keyword and the callback
that the user passes.