diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-with-the-rest-parameter-to-reassign-array-elements.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-with-the-rest-parameter-to-reassign-array-elements.md index ca574e0f174..a73d64685c0 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-with-the-rest-parameter-to-reassign-array-elements.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-with-the-rest-parameter-to-reassign-array-elements.md @@ -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); ```