freeCodeCamp/curriculum/challenges/arabic/02-javascript-algorithms-an.../functional-programming/remove-elements-from-an-arr...

63 lines
1.4 KiB
Markdown

---
id: 9d7123c8c441eeafaeb5bdef
title: Remove Elements from an Array Using slice Instead of splice
challengeType: 1
videoUrl: ''
localeTitle: ''
---
## Description
undefined
## Instructions
undefined
## Tests
<section id='tests'>
```yml
tests:
- text: ''
testString: 'assert(code.match(/\.slice/g), "Your code should use the <code>slice</code> method.");'
- text: ''
testString: 'assert(!code.match(/\.splice/g), "Your code should not use the <code>splice</code> method.");'
- text: ''
testString: 'assert(JSON.stringify(inputCities) === JSON.stringify(["Chicago", "Delhi", "Islamabad", "London", "Berlin"]), "The <code>inputCities</code> array should not change.");'
- text: ''
testString: 'assert(JSON.stringify(nonMutatingSplice(["Chicago", "Delhi", "Islamabad", "London", "Berlin"])) === JSON.stringify(["Chicago", "Delhi", "Islamabad"]), "<code>nonMutatingSplice(["Chicago", "Delhi", "Islamabad", "London", "Berlin"])</code> should return <code>["Chicago", "Delhi", "Islamabad"]</code>.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
function nonMutatingSplice(cities) {
// Add your code below this line
return cities.splice(3);
// Add your code above this line
}
var inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
nonMutatingSplice(inputCities);
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
</section>