LeetCode solutions

2747. Apply Transform Over Each Element in Array

My accepted JavaScript solution to LeetCode problem 2747, Apply Transform Over Each Element in Array, running in 47ms.

  • Difficulty: Easy
  • JavaScript
  • Runtime 47ms
  • Memory 53.7MB

Read the problem on LeetCode View on GitHub

JavaScript

Accepted on LeetCode — runtime 47ms, memory 53.7MB, accepted 2026-01-01.

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

Source