mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-11 07:00:41 -04:00
fix(curriculum): update code order to help with confusion (#48366)
* minor - update order to help with confusion * update variable names, remove source from tests * minor - wording * missing variable rename
This commit is contained in:
committed by
GitHub
parent
cbaa88910e
commit
00f047728b
@@ -27,20 +27,24 @@ Variables `a` and `b` take the first and second values from the array. After tha
|
||||
|
||||
# --instructions--
|
||||
|
||||
Use destructuring assignment with the rest parameter to perform an effective `Array.prototype.slice()` so that `arr` is a sub-array of the original array `source` with the first two elements omitted.
|
||||
Use a destructuring assignment with the rest parameter to emulate the behavior of `Array.prototype.slice()`. `removeFirstTwo()` should return a sub-array of the original array `list` with the first two elements omitted.
|
||||
|
||||
# --hints--
|
||||
|
||||
`arr` should be `[3,4,5,6,7,8,9,10]`
|
||||
`removeFirstTwo([1, 2, 3, 4, 5])` should be `[3, 4, 5]`
|
||||
|
||||
```js
|
||||
assert(arr.every((v, i) => v === i + 3) && arr.length === 8);
|
||||
const testArr_ = [1, 2, 3, 4, 5];
|
||||
const testArrWORemoved_ = removeFirstTwo(testArr_);
|
||||
assert(testArrWORemoved_.every((e, i) => e === i + 3) && testArrWORemoved_.length === 3);
|
||||
```
|
||||
|
||||
`source` should be `[1,2,3,4,5,6,7,8,9,10]`
|
||||
`removeFirstTwo()` should not modify `list`
|
||||
|
||||
```js
|
||||
assert(source.every((v, i) => v === i + 1) && source.length === 10);
|
||||
const testArr_ = [1, 2, 3, 4, 5];
|
||||
const testArrWORemoved_ = removeFirstTwo(testArr_);
|
||||
assert(testArr_.every((e, i) => e === i + 1) && testArr_.length === 5);
|
||||
```
|
||||
|
||||
`Array.slice()` should not be used.
|
||||
@@ -55,7 +59,7 @@ Destructuring on `list` should be used.
|
||||
assert(
|
||||
__helpers
|
||||
.removeWhiteSpace(code)
|
||||
.match(/\[(([_$a-z]\w*)?,){1,}\.\.\.arr\]=list/i)
|
||||
.match(/\[(([_$a-z]\w*)?,){1,}\.\.\.shorterList\]=list/i)
|
||||
);
|
||||
```
|
||||
|
||||
@@ -64,23 +68,25 @@ assert(
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
const source = [1,2,3,4,5,6,7,8,9,10];
|
||||
function removeFirstTwo(list) {
|
||||
// Only change code below this line
|
||||
const arr = list; // Change this line
|
||||
const shorterList = list; // Change this line
|
||||
// Only change code above this line
|
||||
return arr;
|
||||
return shorterList;
|
||||
}
|
||||
const arr = removeFirstTwo(source);
|
||||
|
||||
const source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
const sourceWithoutFirstTwo = removeFirstTwo(source);
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
const source = [1,2,3,4,5,6,7,8,9,10];
|
||||
function removeFirstTwo(list) {
|
||||
const [, , ...arr] = list;
|
||||
return arr;
|
||||
const [, , ...shorterList] = list;
|
||||
return shorterList;
|
||||
}
|
||||
const arr = removeFirstTwo(source);
|
||||
|
||||
const source = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
||||
const sourceWithoutFirstTwo = removeFirstTwo(source);
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user