Skip to content

Commit b69f6d9

Browse files
committed
Add solution #2635
1 parent e06c5eb commit b69f6d9

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@
387387
2629|[Function Composition](./2629-function-composition.js)|Easy|
388388
2630|[Memoize II](./2630-memoize-ii.js)|Hard|
389389
2634|[Filter Elements from Array](./2634-filter-elements-from-array.js)|Easy|
390+
2635|[Apply Transform Over Each Element in Array](./2635-apply-transform-over-each-element-in-array.js)|Easy|
390391
2637|[Promise Time Limit](./2637-promise-time-limit.js)|Medium|
391392
2648|[Generate Fibonacci Sequence](./2648-generate-fibonacci-sequence.js)|Easy|
392393
2649|[Nested Array Generator](./2649-nested-array-generator.js)|Medium|
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* 2635. Apply Transform Over Each Element in Array
3+
* https://leetcode.com/problems/apply-transform-over-each-element-in-array/
4+
* Difficulty: Easy
5+
*
6+
* Given an integer array arr and a mapping function fn, return a new array with a transformation
7+
* applied to each element.
8+
*
9+
* The returned array should be created such that returnedArray[i] = fn(arr[i], i).
10+
*
11+
* Please solve it without the built-in Array.map method.
12+
*/
13+
14+
/**
15+
* @param {number[]} arr
16+
* @param {Function} fn
17+
* @return {number[]}
18+
*/
19+
var map = function(arr, fn) {
20+
const result = [];
21+
22+
for (let i = 0; i < arr.length; i++) {
23+
result.push(fn(arr[i], i));
24+
}
25+
26+
return result;
27+
};

0 commit comments

Comments
 (0)