2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
id: a3566b1109230028080c9345
|
|
|
|
title: Sum All Numbers in a Range
|
|
|
|
isRequired: true
|
|
|
|
challengeType: 5
|
|
|
|
videoUrl: ''
|
|
|
|
localeTitle: 求和范围中的所有数字
|
|
|
|
---
|
|
|
|
|
|
|
|
## Description
|
2020-06-30 01:51:26 -07:00
|
|
|
<section id="description">我们将通过两个数字的数组。返回这两个数字的总和加上它们之间所有数字的总和。最低的数字并不总是第一位。如果卡住,请记得使用<a href="https://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck-coding/19514" target="_blank">Read-Search-Ask</a> 。尝试配对程序。编写自己的代码。 </section>
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
## Instructions
|
|
|
|
<section id="instructions">
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
```yml
|
|
|
|
tests:
|
|
|
|
- text: '<code>sumAll([1, 4])</code>应该返回一个数字。'
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert(typeof sumAll([1, 4]) === 'number');
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: '<code>sumAll([1, 4])</code>应该返回10。'
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(sumAll([1, 4]), 10);
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: '<code>sumAll([4, 1])</code>应该返回10。'
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(sumAll([4, 1]), 10);
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: '<code>sumAll([5, 10])</code>应该返回45。'
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(sumAll([5, 10]), 45);
|
2018-10-10 18:03:03 -04:00
|
|
|
- text: '<code>sumAll([10, 5])</code>应该返回45。'
|
2020-02-18 01:40:55 +09:00
|
|
|
testString: assert.deepEqual(sumAll([10, 5]), 45);
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
<div id='js-seed'>
|
|
|
|
|
|
|
|
```js
|
|
|
|
function sumAll(arr) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
sumAll([1, 4]);
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
<section id='solution'>
|
|
|
|
|
|
|
|
```js
|
|
|
|
// solution required
|
|
|
|
```
|
2020-08-13 17:24:35 +02:00
|
|
|
|
|
|
|
/section>
|