1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-14 01:49:41 +01:00

problems(js): add “2634. Filter Elements from Array”

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2023-05-12 17:31:44 +02:00
parent d18930ad7e
commit 56d6a05ce4
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -0,0 +1,17 @@
/**
* @param {number[]} arr
* @param {Function} fn
* @return {number[]}
*/
var filter = function(arr, fn) {
let new_arr = new Array();
let i = 0;
for (let x of arr) {
if (fn(x, i++)) {
new_arr.push(x);
}
}
return new_arr;
};