1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-09-19 17:56:55 +02: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:
Matej Focko 2023-05-12 17:31:11 +02:00
parent 42c87b3aca
commit d18930ad7e
Signed by: mfocko
GPG key ID: 7C47D46246790496

View 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;
};