回答編集履歴
1
テキスト追加
test
CHANGED
@@ -2,8 +2,42 @@
|
|
2
2
|
|
3
3
|
```javascript
|
4
4
|
|
5
|
+
var numbers = [...Array(100)].map((_ ,i) => i);
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
var x = 5;
|
10
|
+
|
5
|
-
numbers.filter(n => `${n}`.includes(
|
11
|
+
var numbersHavingX = numbers.filter(n => `${n}`.includes(`${x}`));
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
console.log(numbersHavingX); // => [5,15,25,35,45,50,51,52,53,54,55,56,57,58,59,65,75,85,95]
|
16
|
+
|
17
|
+
console.log(numbersHavingX.length); // => 19
|
18
|
+
|
19
|
+
|
6
20
|
|
7
21
|
```
|
8
22
|
|
9
|
-
???? [サンプル](https://codepen.io/kilesa/pen/
|
23
|
+
???? [サンプル](https://codepen.io/kilesa/pen/ZEXBVJv?editors=0012)
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
正規表現を使うのであれば
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
```javascript
|
34
|
+
|
35
|
+
var x = 5;
|
36
|
+
|
37
|
+
var pattern = RegExp(`${x}`);
|
38
|
+
|
39
|
+
var numbersHavingX = numbers.filter(n => pattern.test(`${n}`));
|
40
|
+
|
41
|
+
```
|
42
|
+
|
43
|
+
???? [サンプル](https://codepen.io/kilesa/pen/GRMNPOg?editors=0012)
|