freeCodeCamp/curriculum/challenges/russian/02-javascript-algorithms-an.../basic-javascript/manipulate-arrays-with-shif...

69 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
id: 56bbb991ad1ed5201cd392cd
title: Manipulate Arrays With shift()
challengeType: 1
videoUrl: ''
localeTitle: Манипулировать массивами со сдвигом ()
---
## Description
<section id="description"> <code>pop()</code> всегда удаляет последний элемент массива. Что делать, если вы хотите удалить первый? Вот где <code>.shift()</code> . Он работает так же, как <code>.pop()</code> , за исключением того, что он удаляет первый элемент вместо последнего. </section>
## Instructions
<section id="instructions"> Используйте <code>.shift()</code> чтобы удалить первый элемент из <code>myArray</code> , присвоив значение «shifted off» <code>removedFromMyArray</code> . </section>
## Tests
<section id='tests'>
```yml
tests:
- text: '<code>myArray</code> теперь должен равняться <code>[[&quot;dog&quot;, 3]]</code> .'
testString: 'assert((function(d){if(d[0][0] == "dog" && d[0][1] === 3 && d[1] == undefined){return true;}else{return false;}})(myArray), "<code>myArray</code> should now equal <code>[["dog", 3]]</code>.");'
- text: '<code>removedFromMyArray</code> должен содержать <code>[&quot;John&quot;, 23]</code> .'
testString: 'assert((function(d){if(d[0] == "John" && d[1] === 23 && typeof removedFromMyArray === "object"){return true;}else{return false;}})(removedFromMyArray), "<code>removedFromMyArray</code> should contain <code>["John", 23]</code>.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
// Example
var ourArray = ["Stimpson", "J", ["cat"]];
var removedFromOurArray = ourArray.shift();
// removedFromOurArray now equals "Stimpson" and ourArray now equals ["J", ["cat"]].
// Setup
var myArray = [["John", 23], ["dog", 3]];
// Only change code below this line.
var removedFromMyArray;
```
</div>
### After Test
<div id='js-teardown'>
```js
console.info('after the test');
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>