回答編集履歴
2
ちょうせい
answer
CHANGED
@@ -63,10 +63,8 @@
|
|
63
63
|
},
|
64
64
|
};
|
65
65
|
|
66
|
-
function checkUndefined(arr,obj){
|
67
|
-
|
66
|
+
const checkUndefined=(arr,obj)=>getAllValues(obj).filter(x=>arr.indexOf(x[0])>-1).map(x=>x[1]).indexOf(undefined)>-1;
|
68
|
-
}
|
69
|
-
|
67
|
+
const getAllValues=x=>{
|
70
68
|
var ret=[];
|
71
69
|
Object.entries(x).forEach(y=>{
|
72
70
|
if(y[1] instanceof Object){
|
@@ -76,8 +74,9 @@
|
|
76
74
|
}
|
77
75
|
});
|
78
76
|
return ret;
|
79
|
-
}
|
77
|
+
};
|
80
|
-
console.log(checkUndefined(["p1"],route));
|
78
|
+
console.log(checkUndefined(["p1"],route)); //false
|
81
|
-
console.log(checkUndefined(["p2"],route));
|
79
|
+
console.log(checkUndefined(["p2"],route)); //true
|
82
|
-
console.log(checkUndefined(["p1","p2"],route));
|
80
|
+
console.log(checkUndefined(["p1","p2"],route)); //true
|
81
|
+
console.log(checkUndefined(["p99"],route)); //false
|
83
82
|
```
|
1
ちょうせい
answer
CHANGED
@@ -35,4 +35,49 @@
|
|
35
35
|
return ret;
|
36
36
|
}
|
37
37
|
console.log(getAllValues(route).indexOf(undefined)>-1);
|
38
|
+
```
|
39
|
+
# 特定のkey
|
40
|
+
特定のkeyの部分がぬけてました
|
41
|
+
```javascript
|
42
|
+
var route = {
|
43
|
+
params: {
|
44
|
+
p1: "xxx1",
|
45
|
+
p2: undefined,
|
46
|
+
p3: "xxx1",
|
47
|
+
p4: "xxx1",
|
48
|
+
},
|
49
|
+
params2: {
|
50
|
+
p1: "xxx2",
|
51
|
+
p2: "xxx2",
|
52
|
+
p3: "xxx2",
|
53
|
+
p4: null,
|
54
|
+
},
|
55
|
+
params3: {
|
56
|
+
p1: "xxx3",
|
57
|
+
p2: "xxx3",
|
58
|
+
params4:[
|
59
|
+
"xxx4",
|
60
|
+
undefined,
|
61
|
+
"xxx4",
|
62
|
+
],
|
63
|
+
},
|
64
|
+
};
|
65
|
+
|
66
|
+
function checkUndefined(arr,obj){
|
67
|
+
return getAllValues(obj).filter(x=>arr.indexOf(x[0])>-1).map(x=>x[1]).indexOf(undefined)>-1;
|
68
|
+
}
|
69
|
+
function getAllValues(x){
|
70
|
+
var ret=[];
|
71
|
+
Object.entries(x).forEach(y=>{
|
72
|
+
if(y[1] instanceof Object){
|
73
|
+
ret=ret.concat(getAllValues(y[1]));
|
74
|
+
}else{
|
75
|
+
ret.push(y);
|
76
|
+
}
|
77
|
+
});
|
78
|
+
return ret;
|
79
|
+
}
|
80
|
+
console.log(checkUndefined(["p1"],route));
|
81
|
+
console.log(checkUndefined(["p2"],route));
|
82
|
+
console.log(checkUndefined(["p1","p2"],route));
|
38
83
|
```
|