forked from code-squad/javascript-grade
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectpractice2.js
More file actions
95 lines (93 loc) · 2.14 KB
/
Objectpractice2.js
File metadata and controls
95 lines (93 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
let arr = [{
"id": 1,
name: "Yong",
"phone": "010-2786-9902",
"type": "sk",
"childnode": [{
"id": 11,
"name": "echo",
"phone": "010-3923-1333",
"type": "kt",
"childnode": [{
"id": 115,
name: "hary",
"phone": "010-2786-9302",
"type": "sk",
"childnode": [{
"id": 1159,
"name": "pobi",
"phone": "010-9302-0009",
"type": "kt",
"childnode": [{
"id": 11592,
"name": "cherry",
"phone": "010-1223-9932",
"type": "lg",
"childnode": []
},
{
"id": 11595,
name: "solvin",
"phone": "010-534-7843",
"type": "sk",
"childnode": []
}
]
}]
},
{
"id": 116,
"name": "kim",
"phone": "010-3796-1102",
"type": "kt",
"childnode": [{
"id": 1168,
name: "hani",
"phone": "010-1223-6713",
"type": "sk",
"childnode": [{
"id": 11689,
"name": "ho",
"phone": "010-4434-4534",
"type": "kt",
"childnode": [{
"id": 116890,
"name": "wonsuk",
"phone": "010-3434-1302",
"type": "kt",
"childnode": []
},
{
"id": 1168901,
name: "chulsu",
"phone": "010-3100-9841",
"type": "sk",
"childnode": []
}
]
}]
}]
},
{
"id": 117,
"name": "hong",
"phone": "010-2786-9902",
"type": "lg",
"childnode": []
}
]
}]
}];
function getResult(arr){
if(arr.length === 0) return [];
let result = [];
for(let i = 0; i < arr.length; i++){
if(arr[i]["type"] === "sk"){
result.push(arr[i]["name"]);
}
result = result.concat(getResult(arr[i]["childnode"]));
}
return result;
}
console.log(getResult(arr));
//["Yong", "hary", "solvin", "hani", "chulsu"]