leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE | |
commit | 61b9ff29b9b7c15f338c3463940c910aa3d8612b |
parent | dec44791f7f414b37af8e0cd36f46e82c3450b52 |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Tue, 9 May 2023 16:43:08 +0200 |
JavaScript Challenge: Day 5
Diffstat:A | Problems/2634.js | | | +++++++++++++ |
M | README.md | | | + |
2 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/Problems/2634.js b/Problems/2634.js
@@ -0,0 +1,13 @@
/**
* @param {number[]} arr
* @param {Function} fn
* @return {number[]}
*/
var filter = function(arr, fn) {
var j = 0;
for(let i = 0; i < arr.length; i++)
if(fn(arr[i], i)) arr[j++] = arr[i];
while (arr.length > j) arr.pop();
return arr;
};
diff --git a/README.md b/README.md
@@ -537,6 +537,7 @@ for solving problems.
| 2492 | Medium | [Minimum Score of a Path Between Two Cities](Problems/2492.cpp) |
| 2497 | Medium | [Maximum Star Sum of a Graph](Problems/2497.cpp) |
| 2620 | Easy | [Counter](Problems/2620.js) |
| 2634 | Easy | [Filter Elements from Array](Problems/2634.js) |
| 2635 | Easy | [Apply Transform Over Each Element in Array](Problems/2635.js) |
| 2665 | Easy | [Counter II](Problems/2665.js) |
| 2667 | Easy | [Create Hello World Function](Problems/2667.js) |