File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 387
387
2629|[ Function Composition] ( ./2629-function-composition.js ) |Easy|
388
388
2630|[ Memoize II] ( ./2630-memoize-ii.js ) |Hard|
389
389
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|
390
391
2637|[ Promise Time Limit] ( ./2637-promise-time-limit.js ) |Medium|
391
392
2648|[ Generate Fibonacci Sequence] ( ./2648-generate-fibonacci-sequence.js ) |Easy|
392
393
2649|[ Nested Array Generator] ( ./2649-nested-array-generator.js ) |Medium|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments