From ba415184f6ca28f5fad5dfd87706ad1cd08c351e Mon Sep 17 00:00:00 2001 From: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Date: Tue, 26 Nov 2019 12:14:44 -0800 Subject: [PATCH] fix(curriculum): simplify the Remove Items Using splice() challenge without using reduce (#37829) * fix: simplify challenge without using reduce * fix: prevent user from adding new elements to sum to 10 * fix: add from Co-Authored-By: Manish Giri --- .../remove-items-using-splice.english.md | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/remove-items-using-splice.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/remove-items-using-splice.english.md index 52f1dcf81fc..d0e81d43fe6 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/remove-items-using-splice.english.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-data-structures/remove-items-using-splice.english.md @@ -31,7 +31,9 @@ let newArray = array.splice(3, 2); ## Instructions
-We've defined a function, sumOfTen, which takes an array as an argument and returns the sum of that array's elements. Modify the function, using splice(), so that it returns a value of 10. + +We've initialized an array `arr`. Use `splice()` to remove elements from `arr`, so that it only contains elements that sum to the value of 10. +
## Tests @@ -39,11 +41,14 @@ We've defined a function, sumOfTen, which takes an array as an argu ```yml tests: - - text: sumOfTen should return 10 - testString: assert.strictEqual(sumOfTen([2, 5, 1, 5, 2, 1]), 10); - - text: The sumOfTen function should utilize the splice() method - testString: assert.notStrictEqual(sumOfTen.toString().search(/\.splice\(/), -1); - + - text: You should not change the original line of const arr = [2, 4, 5, 1, 7, 5, 2, 1];. + testString: assert(code.replace(/\s/g, '').match(/constarr=\[2,4,5,1,7,5,2,1\];?/)); + - text: arr should only contain elements that sum to 10. + testString: assert.strictEqual(arr.reduce((a, b) => a + b), 10); + - text: Your code should utilize the splice() method on arr. + testString: assert(code.replace(/\s/g, '').match(/arr\.splice\(/)); + - text: The splice should only remove elements from arr and not add any additional elements to arr. + testString: assert(!code.replace(/\s/g, '').match(/arr\.splice\(\d+,\d+,\d+.*\)/g)); ``` @@ -54,15 +59,11 @@ tests:
```js -function sumOfTen(arr) { - // change code below this line +const arr = [2, 4, 5, 1, 7, 5, 2, 1]; +// only change code below this line - // change code above this line - return arr.reduce((a, b) => a + b); -} - -// do not change code below this line -console.log(sumOfTen([2, 5, 1, 5, 2, 1])); +// only change code above this line +console.log(arr); ```
@@ -75,10 +76,8 @@ console.log(sumOfTen([2, 5, 1, 5, 2, 1]));
```js -function sumOfTen(arr) { - arr.splice(2,2); - return arr.reduce((a, b) => a + b); -} +const arr = [2, 4, 5, 1, 7, 5, 2, 1]; +arr.splice(1, 4); ```