Skip to content

Latest commit

 

History

History
41 lines (30 loc) · 783 Bytes

_2635. Apply Transform Over Each Element in Array.md

File metadata and controls

41 lines (30 loc) · 783 Bytes

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : July 09, 2024

Last updated : July 09, 2024


Related Topics : N/A

Acceptance Rate : 85.88 %


Solutions

JavaScript

/**
 * @param {number[]} arr
 * @param {Function} fn
 * @return {number[]}
 */
var map = function(arr, fn) {
    console.log(fn);
    for (let i = 0; i < arr.length; i++) {
        arr[i] = fn(arr[i], i);
    }
    return arr;
};