2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
id: 587d7b84367417b2b2512b36
|
2020-12-16 00:37:30 -07:00
|
|
|
title: 捕获未闭合的括号、方括号、大括号和引号
|
2018-10-10 18:03:03 -04:00
|
|
|
challengeType: 1
|
2020-09-07 16:09:54 +08:00
|
|
|
forumTopicId: 301190
|
2021-01-13 03:31:00 +01:00
|
|
|
dashedName: catch-unclosed-parentheses-brackets-braces-and-quotes
|
2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --description--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
要注意的另一个语法错误是所有的小括号、方括号、花括号和引号都必须配对。当你编辑代码并插入新代码其中带有括号时,很容易忘记括号闭合。 此外,在将代码块嵌套到其他代码块时要小心,例如将回调函数作为参数添加到方法中。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
避免这种错误的一种方法是,一次性输入完这些符号,然后将光标移回它们之间继续编写。好在,现在大部分编辑器都会帮你自动补全。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --instructions--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
修复代码中的两个符号配对错误。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --hints--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
你应该修复数组缺少的部分。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
```js
|
2020-12-16 00:37:30 -07:00
|
|
|
assert(code.match(/myArray\s*?=\s*?\[\s*?1\s*?,\s*?2\s*?,\s*?3\s*?\];/g));
|
2018-10-10 18:03:03 -04:00
|
|
|
```
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
你应该修复`.reduce()`方法缺少的部分。控制台应输出 "Sum of array values is: 6"。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
```js
|
2020-12-16 00:37:30 -07:00
|
|
|
assert(arraySum === 6);
|
2018-10-10 18:03:03 -04:00
|
|
|
```
|
2020-08-13 17:24:35 +02:00
|
|
|
|
2021-01-13 03:31:00 +01:00
|
|
|
# --seed--
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
```js
|
|
|
|
let myArray = [1, 2, 3;
|
|
|
|
let arraySum = myArray.reduce((previous, current => previous + current);
|
|
|
|
console.log(`Sum of array values is: ${arraySum}`);
|
|
|
|
```
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --solutions--
|
|
|
|
|
2021-01-13 03:31:00 +01:00
|
|
|
```js
|
|
|
|
let myArray = [1, 2, 3];
|
|
|
|
let arraySum = myArray.reduce((previous, current) => previous + current);
|
|
|
|
console.log(`Sum of array values is: ${arraySum}`);
|
|
|
|
```
|