回答編集履歴
4
誤字修正
test
CHANGED
@@ -39,7 +39,7 @@
|
|
39
39
|
console.log(passIndexes); // => [0, 2, 3]
|
40
40
|
```
|
41
41
|
|
42
|
-
【別案3】上の【別案2】
|
42
|
+
【別案3】上の【別案2】を見直したらmapとfilterの2工程で済みました。
|
43
43
|
|
44
44
|
```javascript
|
45
45
|
const array = [ 25, 15, 40, 70, 20 ];
|
3
別案3追加
test
CHANGED
@@ -39,6 +39,15 @@
|
|
39
39
|
console.log(passIndexes); // => [0, 2, 3]
|
40
40
|
```
|
41
41
|
|
42
|
+
【別案3】上の【別案2】の改良して、mapとfilterの2工程で済みました。
|
43
|
+
|
44
|
+
```javascript
|
45
|
+
const array = [ 25, 15, 40, 70, 20 ];
|
46
|
+
const M = 25;
|
47
|
+
const passIndexes = array.map((e, i) => e >= M ? i : -1).filter(n => n >= 0);
|
48
|
+
|
49
|
+
console.log(passIndexes); // => [0, 2, 3]
|
50
|
+
```
|
42
51
|
|
43
52
|
|
44
53
|
|
2
誤字修正
test
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
```
|
13
13
|
とかですかね〜
|
14
14
|
|
15
|
-
【別案1】
|
15
|
+
【別案1】再帰関数
|
16
16
|
```javascript
|
17
17
|
const findIndexes = (ary, min, start=0) => {
|
18
18
|
const index = ary.findIndex(e => e >= min);
|
@@ -27,7 +27,7 @@
|
|
27
27
|
|
28
28
|
console.log(passIndexes); // => [0, 2, 3]
|
29
29
|
```
|
30
|
-
とする
|
30
|
+
とする。
|
31
31
|
|
32
32
|
|
33
33
|
【別案2】mapしてfilterしてまたmapするっていう3工程になってしまうけれど、
|
@@ -38,8 +38,8 @@
|
|
38
38
|
|
39
39
|
console.log(passIndexes); // => [0, 2, 3]
|
40
40
|
```
|
41
|
-
とするとか。
|
42
41
|
|
43
42
|
|
44
43
|
|
45
44
|
|
45
|
+
|
1
別案を追加
test
CHANGED
@@ -11,3 +11,35 @@
|
|
11
11
|
console.log(passIndexes); // => [0, 2, 3]
|
12
12
|
```
|
13
13
|
とかですかね〜
|
14
|
+
|
15
|
+
【別案1】それか、再帰関数
|
16
|
+
```javascript
|
17
|
+
const findIndexes = (ary, min, start=0) => {
|
18
|
+
const index = ary.findIndex(e => e >= min);
|
19
|
+
return index >= 0 ? [start+index, ...findIndexes(ary.slice(index+1), min, start+index+1)] : [];
|
20
|
+
}
|
21
|
+
```
|
22
|
+
というのを作っておいて、
|
23
|
+
```javascript
|
24
|
+
const array = [ 25, 15, 40, 70, 20 ];
|
25
|
+
const M = 25;
|
26
|
+
const passIndexes = findIndexes(array, M);
|
27
|
+
|
28
|
+
console.log(passIndexes); // => [0, 2, 3]
|
29
|
+
```
|
30
|
+
とするかとか。
|
31
|
+
|
32
|
+
|
33
|
+
【別案2】mapしてfilterしてまたmapするっていう3工程になってしまうけれど、
|
34
|
+
```javascript
|
35
|
+
const array = [ 25, 15, 40, 70, 20 ];
|
36
|
+
const M = 25;
|
37
|
+
const passIndexes = array.map((e, i) => ({ e, i })).filter(({ e }) => e >= M).map(({ i }) => i);
|
38
|
+
|
39
|
+
console.log(passIndexes); // => [0, 2, 3]
|
40
|
+
```
|
41
|
+
とするとか。
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
|