回答編集履歴
2
ちょうせい
test
CHANGED
@@ -128,13 +128,9 @@
|
|
128
128
|
|
129
129
|
|
130
130
|
|
131
|
-
|
131
|
+
const checkUndefined=(arr,obj)=>getAllValues(obj).filter(x=>arr.indexOf(x[0])>-1).map(x=>x[1]).indexOf(undefined)>-1;
|
132
132
|
|
133
|
-
return getAllValues(obj).filter(x=>arr.indexOf(x[0])>-1).map(x=>x[1]).indexOf(undefined)>-1;
|
134
|
-
|
135
|
-
}
|
136
|
-
|
137
|
-
|
133
|
+
const getAllValues=x=>{
|
138
134
|
|
139
135
|
var ret=[];
|
140
136
|
|
@@ -154,12 +150,14 @@
|
|
154
150
|
|
155
151
|
return ret;
|
156
152
|
|
157
|
-
}
|
153
|
+
};
|
158
154
|
|
159
|
-
console.log(checkUndefined(["p1"],route));
|
155
|
+
console.log(checkUndefined(["p1"],route)); //false
|
160
156
|
|
161
|
-
console.log(checkUndefined(["p2"],route));
|
157
|
+
console.log(checkUndefined(["p2"],route)); //true
|
162
158
|
|
163
|
-
console.log(checkUndefined(["p1","p2"],route));
|
159
|
+
console.log(checkUndefined(["p1","p2"],route)); //true
|
160
|
+
|
161
|
+
console.log(checkUndefined(["p99"],route)); //false
|
164
162
|
|
165
163
|
```
|
1
ちょうせい
test
CHANGED
@@ -73,3 +73,93 @@
|
|
73
73
|
console.log(getAllValues(route).indexOf(undefined)>-1);
|
74
74
|
|
75
75
|
```
|
76
|
+
|
77
|
+
# 特定のkey
|
78
|
+
|
79
|
+
特定のkeyの部分がぬけてました
|
80
|
+
|
81
|
+
```javascript
|
82
|
+
|
83
|
+
var route = {
|
84
|
+
|
85
|
+
params: {
|
86
|
+
|
87
|
+
p1: "xxx1",
|
88
|
+
|
89
|
+
p2: undefined,
|
90
|
+
|
91
|
+
p3: "xxx1",
|
92
|
+
|
93
|
+
p4: "xxx1",
|
94
|
+
|
95
|
+
},
|
96
|
+
|
97
|
+
params2: {
|
98
|
+
|
99
|
+
p1: "xxx2",
|
100
|
+
|
101
|
+
p2: "xxx2",
|
102
|
+
|
103
|
+
p3: "xxx2",
|
104
|
+
|
105
|
+
p4: null,
|
106
|
+
|
107
|
+
},
|
108
|
+
|
109
|
+
params3: {
|
110
|
+
|
111
|
+
p1: "xxx3",
|
112
|
+
|
113
|
+
p2: "xxx3",
|
114
|
+
|
115
|
+
params4:[
|
116
|
+
|
117
|
+
"xxx4",
|
118
|
+
|
119
|
+
undefined,
|
120
|
+
|
121
|
+
"xxx4",
|
122
|
+
|
123
|
+
],
|
124
|
+
|
125
|
+
},
|
126
|
+
|
127
|
+
};
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
function checkUndefined(arr,obj){
|
132
|
+
|
133
|
+
return getAllValues(obj).filter(x=>arr.indexOf(x[0])>-1).map(x=>x[1]).indexOf(undefined)>-1;
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
function getAllValues(x){
|
138
|
+
|
139
|
+
var ret=[];
|
140
|
+
|
141
|
+
Object.entries(x).forEach(y=>{
|
142
|
+
|
143
|
+
if(y[1] instanceof Object){
|
144
|
+
|
145
|
+
ret=ret.concat(getAllValues(y[1]));
|
146
|
+
|
147
|
+
}else{
|
148
|
+
|
149
|
+
ret.push(y);
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
});
|
154
|
+
|
155
|
+
return ret;
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
console.log(checkUndefined(["p1"],route));
|
160
|
+
|
161
|
+
console.log(checkUndefined(["p2"],route));
|
162
|
+
|
163
|
+
console.log(checkUndefined(["p1","p2"],route));
|
164
|
+
|
165
|
+
```
|