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
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
JavaScript
Accepted on LeetCode — runtime 47ms, memory 53.7MB, accepted 2026-01-01.
/**
* @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;
};