FrontendChallenges is a collection of frontend interview questions and answers. It is designed to help you prepare for frontend interviews. It's free and open source.
Implement a custom arrayMap function that mimics the behavior of the native map method.
The arrayMap function should take an array and a callback function as arguments. The callback function should be invoked with three arguments: the current element, the index of the current element, and the array itself. The arrayMap function should return a new array containing the results of applying the callback function to each element of the original array.
Use the following example to understand how the arrayMap function should work:
Info
Question
Implement a custom
arrayMap
function that mimics the behavior of the nativemap
method.The
arrayMap
function should take an array and a callback function as arguments. The callback function should be invoked with three arguments: the current element, the index of the current element, and the array itself. ThearrayMap
function should return a new array containing the results of applying the callback function to each element of the original array.Use the following example to understand how the
arrayMap
function should work:Template
index.js
index.test.js