mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-10 00:09:06 +01:00
problems(js): add “2635. Apply Transform Over Each Element in Array”
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
42c87b3aca
commit
d18930ad7e
1 changed files with 15 additions and 0 deletions
15
problems/apply-transform-over-each-element-in-array.js
Normal file
15
problems/apply-transform-over-each-element-in-array.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
/**
|
||||
* @param {number[]} arr
|
||||
* @param {Function} fn
|
||||
* @return {number[]}
|
||||
*/
|
||||
var map = function(arr, fn) {
|
||||
let mapped_arr = new Array();
|
||||
|
||||
let i = 0;
|
||||
for (let x of arr) {
|
||||
mapped_arr.push(fn(x, i++));
|
||||
}
|
||||
|
||||
return mapped_arr;
|
||||
};
|
Loading…
Reference in a new issue