質問編集履歴
3
objを修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -62,7 +62,7 @@
|
|
62
62
|
|
63
63
|
```TypeScript
|
64
64
|
|
65
|
-
obj = {11: 2, 12: 1}
|
65
|
+
obj = {'11': 2, '12': 1}
|
66
66
|
|
67
67
|
|
68
68
|
|
2
自分で試したコードを添付
test
CHANGED
File without changes
|
test
CHANGED
@@ -56,4 +56,56 @@
|
|
56
56
|
|
57
57
|
|
58
58
|
|
59
|
+
###自分で試したこと
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
```TypeScript
|
64
|
+
|
65
|
+
obj = {11: 2, 12: 1}
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
const result: any = numbers.map(((number: any) => {
|
70
|
+
|
71
|
+
var index = 0
|
72
|
+
|
73
|
+
for (let i = 0; Object.keys(obj).length; i++ ){
|
74
|
+
|
75
|
+
if (number.toString() == Object.keys(obj)[index]){
|
76
|
+
|
77
|
+
return Object.values(obj)[index]
|
78
|
+
|
79
|
+
} else {
|
80
|
+
|
81
|
+
return 0
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
index++
|
88
|
+
|
89
|
+
}))
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
console.log(result)
|
94
|
+
|
95
|
+
```
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
```
|
100
|
+
|
101
|
+
//出力結果
|
102
|
+
|
103
|
+
result = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0]
|
104
|
+
|
105
|
+
```
|
106
|
+
|
107
|
+
このようになってしまって、12の1がなぜか出力されない状況です。
|
108
|
+
|
109
|
+
|
110
|
+
|
59
111
|
アルゴリズムに詳しい方、ご回答よろしくお願いいたします。
|
1
keyを文字列に変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -4,15 +4,15 @@
|
|
4
4
|
|
5
5
|
```javaScript
|
6
6
|
|
7
|
-
obj1 ={1:2, 2:4, 4:2, 8:2 , 9:1, 12:1}
|
7
|
+
obj1 ={'1':2, '2':4, '4':2, '8':2 , '9':1, '12':1}
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
obj2 ={2:2, 4:4, 6:2, 10:2}
|
11
|
+
obj2 ={'2':2, '4':4, '6':2, '10':2}
|
12
12
|
|
13
13
|
|
14
14
|
|
15
|
-
obj3 ={3:2, 4:4, 5:2, 6:2 , 9:1, 11:1, 12:3}
|
15
|
+
obj3 ={'3':2, '4':4, '5':2, '6':2 , '9':1, '11':1, '12':3}
|
16
16
|
|
17
17
|
```
|
18
18
|
|
@@ -38,15 +38,15 @@
|
|
38
38
|
|
39
39
|
```javaScript
|
40
40
|
|
41
|
-
result1 ={1:2, 2:4, 3:0, 4:2, 5:0, 6:0, 7:0, 8:2, 9:1, 10:0, 11:0, 12:1}
|
41
|
+
result1 ={'1':2, '2':4, '3':0, '4':2, '5':0, '6':0, '7':0, '8':2, '9':1, '10':0, '11':0, '12':1}
|
42
42
|
|
43
43
|
|
44
44
|
|
45
|
-
result2 ={1,0 ,2:2, 3,0, 4:4, 5:0, 6:2, 7:0, 8:0, 9:0, 10:2, 11:0, 12:0}
|
45
|
+
result2 ={'1',0 ,'2':2, '3',0, '4':4, '5':0, '6':2, '7':0, '8':0, '9':0, '10':2, '11':0, '12':0}
|
46
46
|
|
47
47
|
|
48
48
|
|
49
|
-
result3 ={1:0, 2:0, 3:2, 4:4, 5:2, 6:2, 7:0, 8:0, 9:1, 10:0, 11:1, 12:3}
|
49
|
+
result3 ={'1':0, '2':0, '3':2, '4':4, '5':2, '6':2, '7':0, '8':0, '9':1, '10':0, '11':1, '12':3}
|
50
50
|
|
51
51
|
```
|
52
52
|
|