質問編集履歴
1
コードの追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -73,3 +73,169 @@
|
|
73
73
|
できればブラウザ上で変化する値に応じて処理を変えたいので、Javascriptだけで記述したいです。
|
74
74
|
|
75
75
|
上手く伝わっているかわかりませんが、ご助力よろしくお願いします。
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
――追記――
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
配列の中の数値を2つ以上足した数値をすべて取り出したいです。
|
84
|
+
|
85
|
+
そしてこの配列の中の数値や個数が変化する前提で記述したいです。
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
```Javascript
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
var money = [500,100,100,50,10,5];
|
94
|
+
|
95
|
+
var pattern = [];
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
for(i=0; i<money.length-1; i++){
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
for(j=i+1; j<money.length; j++){
|
104
|
+
|
105
|
+
sum = 0;
|
106
|
+
|
107
|
+
sum += money[i];
|
108
|
+
|
109
|
+
sum += money[j];
|
110
|
+
|
111
|
+
if(!pattern.includes(sum)){
|
112
|
+
|
113
|
+
pattern.push(sum);
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
for(k=j+1; k<money.length; k++){
|
120
|
+
|
121
|
+
sum = 0;
|
122
|
+
|
123
|
+
sum += money[i];
|
124
|
+
|
125
|
+
sum += money[j];
|
126
|
+
|
127
|
+
sum += money[k];
|
128
|
+
|
129
|
+
if(!pattern.includes(sum)){
|
130
|
+
|
131
|
+
pattern.push(sum);
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
for(l=k+1; l<money.length; l++){
|
138
|
+
|
139
|
+
sum = 0;
|
140
|
+
|
141
|
+
sum += money[i];
|
142
|
+
|
143
|
+
sum += money[j];
|
144
|
+
|
145
|
+
sum += money[k];
|
146
|
+
|
147
|
+
sum += money[l];
|
148
|
+
|
149
|
+
if(!pattern.includes(sum)){
|
150
|
+
|
151
|
+
pattern.push(sum);
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
for(m=l+1; m<money.length; m++){
|
158
|
+
|
159
|
+
sum = 0;
|
160
|
+
|
161
|
+
sum += money[i];
|
162
|
+
|
163
|
+
sum += money[j];
|
164
|
+
|
165
|
+
sum += money[k];
|
166
|
+
|
167
|
+
sum += money[l];
|
168
|
+
|
169
|
+
sum += money[m];
|
170
|
+
|
171
|
+
if(!pattern.includes(sum)){
|
172
|
+
|
173
|
+
pattern.push(sum);
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
for(n=m+1; n<money.length; n++){
|
180
|
+
|
181
|
+
sum = 0;
|
182
|
+
|
183
|
+
sum += money[i];
|
184
|
+
|
185
|
+
sum += money[j];
|
186
|
+
|
187
|
+
sum += money[k];
|
188
|
+
|
189
|
+
sum += money[l];
|
190
|
+
|
191
|
+
sum += money[m];
|
192
|
+
|
193
|
+
sum += money[n];
|
194
|
+
|
195
|
+
if(!pattern.includes(sum)){
|
196
|
+
|
197
|
+
pattern.push(sum);
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
for(o=n+1; o<money.length; o++){
|
204
|
+
|
205
|
+
sum = 0;
|
206
|
+
|
207
|
+
sum += money[i];
|
208
|
+
|
209
|
+
sum += money[j];
|
210
|
+
|
211
|
+
sum += money[k];
|
212
|
+
|
213
|
+
sum += money[l];
|
214
|
+
|
215
|
+
sum += money[m];
|
216
|
+
|
217
|
+
sum += money[n];
|
218
|
+
|
219
|
+
sum += money[o];
|
220
|
+
|
221
|
+
if(!pattern.includes(sum)){
|
222
|
+
|
223
|
+
pattern.push(sum);
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
}
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
}
|
234
|
+
|
235
|
+
}
|
236
|
+
|
237
|
+
}
|
238
|
+
|
239
|
+
}
|
240
|
+
|
241
|
+
```
|