Skip to content

Commit 48bba06

Browse files
authored
Create 2634-filter-elements-from-array.js (#3731)
1 parent c071774 commit 48bba06

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @param {number[]} arr
3+
* @param {Function} fn
4+
* @return {number[]}
5+
*/
6+
var filter = function (arr, fn) {
7+
ans = [];
8+
for (let i = 0; i < arr.length; i++)
9+
if (fn(arr[i], i))
10+
ans.push(arr[i]);
11+
return ans;
12+
};

0 commit comments

Comments
 (0)