回答編集履歴

1

調整

2021/06/21 07:14

投稿

yambejp
yambejp

スコア116724

test CHANGED
@@ -1,11 +1,19 @@
1
1
  ```javascript
2
2
 
3
- const str= "1212121,343434,56757,7878787"
3
+ const str= "3434,1212121,43434,56757,7878787"
4
4
 
5
- const check=(keyword,str)=>RegExp(`(^|,)${keyword}(?=,|$)`).test(str);
5
+ const check1=(keyword,str)=>RegExp(`(^|,)${keyword}(?=,|$)`).test(str);//正規表現
6
6
 
7
- console.log(check("343434",str));
7
+ const check2=(keyword,str)=>str.split(",").includes(keyword);//配列
8
8
 
9
+ console.log(check1("343434",str));
10
+
9
- console.log(check("3434",str));
11
+ console.log(check1("3434",str));
12
+
13
+ console.log(check2("343434",str));
14
+
15
+ console.log(check2("3434",str));
16
+
17
+
10
18
 
11
19
  ```