teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

括弧が含まれる場合に修正

2017/08/27 09:37

投稿

chitoku
chitoku

スコア1610

answer CHANGED
@@ -3,7 +3,7 @@
3
3
  ```typescript
4
4
  splitByBadge(subject: string): string[] {
5
5
  return subject.split(/(?=\(.*\))/).reduce((array, str) => {
6
- if (/^\(.*\)$/.test(str)) {
6
+ if (/[()]/.test(str)) {
7
7
  array.push((array.pop() || "") + str);
8
8
  return array;
9
9
  }

1

concat

2017/08/27 09:37

投稿

chitoku
chitoku

スコア1610

answer CHANGED
@@ -7,8 +7,7 @@
7
7
  array.push((array.pop() || "") + str);
8
8
  return array;
9
9
  }
10
- array.push(...str.split(/(?=[^(\]]\[.\].*)/));
10
+ return array.concat(str.split(/(?=[^(\]]\[.\].*)/));
11
- return array;
12
11
  }, []);
13
12
  }
14
13