回答編集履歴

2

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

2017/08/27 09:37

投稿

chitoku
chitoku

スコア1610

test CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  return subject.split(/(?=\(.*\))/).reduce((array, str) => {
10
10
 
11
- if (/^\(.*\)$/.test(str)) {
11
+ if (/[()]/.test(str)) {
12
12
 
13
13
  array.push((array.pop() || "") + str);
14
14
 

1

concat

2017/08/27 09:37

投稿

chitoku
chitoku

スコア1610

test CHANGED
@@ -16,9 +16,7 @@
16
16
 
17
17
  }
18
18
 
19
- array.push(...str.split(/(?=[^(\]]\[.\].*)/));
19
+ return array.concat(str.split(/(?=[^(\]]\[.\].*)/));
20
-
21
- return array;
22
20
 
23
21
  }, []);
24
22