We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1f5370f commit e8096afCopy full SHA for e8096af
Interview Question/deepFilter.js
@@ -1 +1,36 @@
1
2
+// https://leetcode.com/discuss/interview-question/328553/amazon-phone-screen-deep-filter
3
+const filter = (s) => typeof s === "string";
4
+const obj = {
5
+ a: 1,
6
+ b: {
7
+ c: "Hello World",
8
+ d: 2,
9
+ e: {
10
+ f: {
11
+ g: -4,
12
+ },
13
14
+ h: "Good Night Moon",
15
16
+};
17
+
18
+const deepFilter = (obj, filter) => {
19
+ for (const key in obj) {
20
+ const value = obj[key];
21
+ if (typeof value === "object") {
22
+ deepFilter(value, filter);
23
+ } else {
24
+ if (!filter(value)) {
25
+ delete obj[key];
26
+ }
27
28
29
+ if (typeof obj[key] === "object" && Object.entries(obj[key]).length === 0) {
30
31
32
33
34
35
+deepFilter(obj, filter);
36
+console.log(obj);
0 commit comments