Files
.github
api-server
client
config
curriculum
challenges
_meta
arabic
chinese
01-responsive-web-design
02-javascript-algorithms-and-data-structures
basic-algorithm-scripting
basic-data-structures
access-an-arrays-contents-using-bracket-notation.chinese.md
access-property-names-with-bracket-notation.chinese.md
add-items-to-an-array-with-push-and-unshift.chinese.md
add-items-using-splice.chinese.md
add-key-value-pairs-to-javascript-objects.chinese.md
check-for-the-presence-of-an-element-with-indexof.chinese.md
check-if-an-object-has-a-property.chinese.md
combine-arrays-with-the-spread-operator.chinese.md
copy-an-array-with-the-spread-operator.chinese.md
copy-array-items-using-slice.chinese.md
create-complex-multi-dimensional-arrays.chinese.md
generate-an-array-of-all-object-keys-with-object.keys.chinese.md
iterate-through-all-an-arrays-items-using-for-loops.chinese.md
iterate-through-the-keys-of-an-object-with-a-for...in-statement.chinese.md
modify-an-array-stored-in-an-object.chinese.md
modify-an-object-nested-within-an-object.chinese.md
remove-items-from-an-array-with-pop-and-shift.chinese.md
remove-items-using-splice.chinese.md
use-an-array-to-store-a-collection-of-data.chinese.md
use-the-delete-keyword-to-remove-object-properties.chinese.md
basic-javascript
debugging
es6
functional-programming
intermediate-algorithm-scripting
javascript-algorithms-and-data-structures-projects
object-oriented-programming
regular-expressions
03-front-end-libraries
04-data-visualization
05-apis-and-microservices
06-information-security-and-quality-assurance
08-coding-interview-prep
09-certificates
english
portuguese
russian
spanish
schema
test
.babelrc
.editorconfig
.npmignore
.travis.yml
CHANGELOG.md
LICENSE.md
commitizen.config.js
commitlint.config.js
create-challenge-bundle.js
getChallenges.js
gulpfile.js
lib.js
package-entry.js
package-lock.json
package.json
utils.js
cypress
docs
search-indexing
tools
utils
.editorconfig
.eslintignore
.eslintrc.json
.gitattributes
.gitignore
.gitpod.yml
.node-inspectorrc
.npmrc
.prettierignore
.prettierrc
.snyk
.travis.yml
.vcmrc
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Dockerfile.tests
HoF.md
LICENSE.md
README.md
SECURITY.md
change_volumes_owner.sh
cypress-install.js
cypress.json
docker-compose-shared.yml
docker-compose.tests.yml
docker-compose.yml
jest.config.js
lerna.json
package-lock.json
package.json
sample.env
Kristofer Koishigawa b3213fc892 fix(i18n): chinese test suite ()
* fix: Chinese test suite

Add localeTiltes, descriptions, and adjust test text and testStrings to get the automated test suite working.

* fix: ran script, updated testStrings and solutions
2020-03-03 18:49:47 +05:30

59 lines
2.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
id: 587d7b7a367417b2b2512b12
title: Copy Array Items Using slice()
challengeType: 1
videoUrl: ''
localeTitle: 使用slice复制数组项
---
## Description
<section id="description">我们将介绍的下一个方法是<code>slice()</code><code>slice()</code> ,而不是修改数组,将给定数量的元素复制或<em>提取</em>到新数组,而不改变它所调用的数组。 <code>slice()</code>只接受2个参数 - 第一个是开始提取的索引,第二个是停止提取的索引(提取将发生,但不包括此索引处的元素)。考虑一下: <blockquote>让weatherConditions = [&#39;rain&#39;&#39;snow&#39;&#39;sleet&#39;&#39;hail&#39;&#39;clear&#39;]; <br><br>让todaysWeather = weatherConditions.slice1,3; <br> //今天天气等于[&#39;&#39;&#39;雨夹雪&#39;]; <br> // weatherConditions仍等于[&#39;rain&#39;&#39;snow&#39;&#39;sleet&#39;&#39;hail&#39;&#39;clear&#39;] <br></blockquote>实际上,我们通过从现有数组中提取元素来创建一个新数组。 </section>
## Instructions
<section id="instructions">我们定义了一个以数组作为参数的函数<code>forecast</code> 。使用<code>slice()</code>修改函数以从参数数组中提取信息,并返回包含元素<code>&#39;warm&#39;</code><code>&#39;sunny&#39;</code>的新数组。 </section>
## Tests
<section id='tests'>
```yml
tests:
- text: '<code>forecast</code>应该返回<code>[&quot;warm&quot;, &quot;sunny&quot;]</code>'
testString: assert.deepEqual(forecast(['cold', 'rainy', 'warm', 'sunny', 'cool', 'thunderstorms']), ['warm', 'sunny']);
- text: <code>forecast</code>函数应该使用<code>slice()</code>方法
testString: assert(/\.slice\(/.test(code));
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
function forecast(arr) {
// change code below this line
return arr;
}
// do not change code below this line
console.log(forecast(['cold', 'rainy', 'warm', 'sunny', 'cool', 'thunderstorms']));
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>