From 4fbce07792600bee2dfd3ef476a694f1311ab76c Mon Sep 17 00:00:00 2001 From: Hassaan Pasha Date: Thu, 26 Mar 2020 20:13:34 +0500 Subject: [PATCH] fix: improve test regex to validate disallowed methods that can be bypassed by prototype reassignments and/or otherwise (#38214) * fix: improve test regex to validate disallowed methods that can be bypassed by prototype reassignments and/or otherwise * fix: fixing regex pattern --- ...of-an-array-using-concat-instead-of-push.english.md | 2 +- ...gramming-to-convert-strings-to-url-slugs.english.md | 2 +- ...rray-into-a-string-using-the-join-method.english.md | 2 +- .../implement-map-on-a-prototype.english.md | 2 +- ...plement-the-filter-method-on-a-prototype.english.md | 2 +- ...m-an-array-using-slice-instead-of-splice.english.md | 2 +- .../steamroller.english.md | 10 ++++++---- .../remove-whitespace-from-start-and-end.english.md | 2 +- .../algorithms/implement-bubble-sort.english.md | 2 +- .../algorithms/implement-insertion-sort.english.md | 2 +- .../algorithms/implement-merge-sort.english.md | 2 +- .../algorithms/implement-quick-sort.english.md | 2 +- .../algorithms/implement-selection-sort.english.md | 2 +- 13 files changed, 18 insertions(+), 16 deletions(-) diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.english.md index 43485eae8b..d018f1db5c 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.english.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.english.md @@ -33,7 +33,7 @@ tests: - text: Your code should use the concat method. testString: assert(code.match(/\.concat/g)); - text: Your code should not use the push method. - testString: assert(!code.match(/\.push/g)); + testString: assert(!code.match(/\.?[\s\S]*?push/g)); - text: The first array should not change. testString: assert(JSON.stringify(first) === JSON.stringify([1, 2, 3])); - text: The second array should not change. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.english.md index 3bcebd0a81..eb87a3490f 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.english.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.english.md @@ -29,7 +29,7 @@ tests: - text: The globalTitle variable should not change. testString: assert(globalTitle === "Winter Is Coming"); - text: Your code should not use the replace method for this challenge. - testString: assert(!code.match(/\.replace/g)); + testString: assert(!code.match(/\.?[\s\S]*?replace/g)); - text: urlSlug("Winter Is Coming") should return "winter-is-coming". testString: assert(urlSlug("Winter Is Coming") === "winter-is-coming"); - text: urlSlug(" Winter Is  Coming") should return "winter-is-coming". diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.english.md index d94bb3c41c..ee7afe2378 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.english.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.english.md @@ -31,7 +31,7 @@ tests: - text: Your code should use the join method. testString: assert(code.match(/\.join/g)); - text: Your code should not use the replace method. - testString: assert(!code.match(/\.replace/g)); + testString: assert(!code.match(/\.?[\s\S]*?replace/g)); - text: sentensify("May-the-force-be-with-you") should return a string. testString: assert(typeof sentensify("May-the-force-be-with-you") === "string"); - text: sentensify("May-the-force-be-with-you") should return "May the force be with you". diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.english.md index b0589dc2e8..a3bbaf1855 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.english.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.english.md @@ -26,7 +26,7 @@ tests: - text: new_s should equal [46, 130, 196, 10]. testString: assert(JSON.stringify(new_s) === JSON.stringify([46, 130, 196, 10])); - text: Your code should not use the map method. - testString: assert(!code.match(/\.map/g)); + testString: assert(!code.match(/\.?[\s\S]*?map/g)); ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/implement-the-filter-method-on-a-prototype.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/implement-the-filter-method-on-a-prototype.english.md index 7132270886..d26c2961f1 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/implement-the-filter-method-on-a-prototype.english.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/implement-the-filter-method-on-a-prototype.english.md @@ -24,7 +24,7 @@ tests: - text: new_s should equal [23, 65, 5]. testString: assert(JSON.stringify(new_s) === JSON.stringify([23, 65, 5])); - text: Your code should not use the filter method. - testString: assert(!code.match(/\.filter/g)); + testString: assert(!code.match(/\.?[\s\S]*?filter/g)); ``` diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.english.md index 3d06097ed3..d3b5e3ffd1 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.english.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.english.md @@ -32,7 +32,7 @@ tests: - text: Your code should use the slice method. testString: assert(code.match(/\.slice/g)); - text: Your code should not use the splice method. - testString: assert(!code.match(/\.splice/g)); + testString: assert(!code.match(/\.?[\s\S]*?splice/g)); - text: The inputCities array should not change. testString: assert(JSON.stringify(inputCities) === JSON.stringify(["Chicago", "Delhi", "Islamabad", "London", "Berlin"])); - text: nonMutatingSplice(["Chicago", "Delhi", "Islamabad", "London", "Berlin"]) should return ["Chicago", "Delhi", "Islamabad"]. diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/steamroller.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/steamroller.english.md index fc698e38b2..fa0d52c18b 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/steamroller.english.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/steamroller.english.md @@ -7,16 +7,19 @@ forumTopicId: 16079 --- ## Description +
Flatten a nested array. You must account for varying levels of nesting.
## Instructions +
## Tests +
```yml @@ -30,12 +33,13 @@ tests: - text: steamrollArray([1, {}, [3, [[4]]]]) should return [1, {}, 3, 4]. testString: assert.deepEqual(steamrollArray([1, {}, [3, [[4]]]]), [1, {}, 3, 4]); - text: Your solution should not use the Array.prototype.flat() or Array.prototype.flatMap() methods. - testString: assert(!code.match(/\.flat\([\s\S]*?\)/) && !code.match(/\.flatMap\([\s\S]*?\)/)); + testString: assert(!code.match(/\.?[\s\S]*?flat/) && !code.match(/\.?[\s\S]*?flatMap/)); ```
## Challenge Seed +
@@ -50,13 +54,11 @@ steamrollArray([1, [2], [3, [[4]]]]);
- -
## Solution -
+
```js function steamrollArray(arr) { diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/remove-whitespace-from-start-and-end.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/remove-whitespace-from-start-and-end.english.md index e198232222..6c9e330751 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/remove-whitespace-from-start-and-end.english.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/regular-expressions/remove-whitespace-from-start-and-end.english.md @@ -24,7 +24,7 @@ tests: - text: result should equal to "Hello, World!" testString: assert(result == "Hello, World!"); - text: Your solution should not use the String.prototype.trim() method. - testString: assert(!code.match(/\.trim\([\s\S]*?\)/)); + testString: assert(!code.match(/\.?[\s\S]*?trim/)); - text: The result variable should not be set equal to a string. testString: assert(!code.match(/result\s*=\s*".*?"/)); diff --git a/curriculum/challenges/english/08-coding-interview-prep/algorithms/implement-bubble-sort.english.md b/curriculum/challenges/english/08-coding-interview-prep/algorithms/implement-bubble-sort.english.md index 3ba8ea0a7f..36fc5101be 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/algorithms/implement-bubble-sort.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/algorithms/implement-bubble-sort.english.md @@ -31,7 +31,7 @@ tests: - text: bubbleSort should return an array that is unchanged except for order. testString: assert.sameMembers(bubbleSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]); - text: bubbleSort should not use the built-in .sort() method. - testString: assert.strictEqual(code.search(/\.sort\(/), -1); + testString: assert(!code.match(/\.?[\s\S]*?sort/)); ``` diff --git a/curriculum/challenges/english/08-coding-interview-prep/algorithms/implement-insertion-sort.english.md b/curriculum/challenges/english/08-coding-interview-prep/algorithms/implement-insertion-sort.english.md index 004af42355..6bfce6b530 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/algorithms/implement-insertion-sort.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/algorithms/implement-insertion-sort.english.md @@ -29,7 +29,7 @@ tests: - text: insertionSort should return an array that is unchanged except for order. testString: assert.sameMembers(insertionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]); - text: insertionSort should not use the built-in .sort() method. - testString: assert.strictEqual(code.search(/\.sort\(/), -1); + testString: assert(!code.match(/\.?[\s\S]*?sort/)); ``` diff --git a/curriculum/challenges/english/08-coding-interview-prep/algorithms/implement-merge-sort.english.md b/curriculum/challenges/english/08-coding-interview-prep/algorithms/implement-merge-sort.english.md index 8fd7f7a0be..df2bda05c5 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/algorithms/implement-merge-sort.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/algorithms/implement-merge-sort.english.md @@ -33,7 +33,7 @@ tests: - text: mergeSort should return an array that is unchanged except for order. testString: assert.sameMembers(mergeSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]); - text: mergeSort should not use the built-in .sort() method. - testString: assert.strictEqual(code.search(/\.sort\(/), -1); + testString: assert(!code.match(/\.?[\s\S]*?sort/)); ``` diff --git a/curriculum/challenges/english/08-coding-interview-prep/algorithms/implement-quick-sort.english.md b/curriculum/challenges/english/08-coding-interview-prep/algorithms/implement-quick-sort.english.md index 23b8a30104..babda81e11 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/algorithms/implement-quick-sort.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/algorithms/implement-quick-sort.english.md @@ -30,7 +30,7 @@ tests: - text: quickSort should return an array that is unchanged except for order. testString: assert.sameMembers(quickSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]); - text: quickSort should not use the built-in .sort() method. - testString: assert.strictEqual(code.search(/\.sort\(/), -1); + testString: assert(!code.match(/\.?[\s\S]*?sort/)); ``` diff --git a/curriculum/challenges/english/08-coding-interview-prep/algorithms/implement-selection-sort.english.md b/curriculum/challenges/english/08-coding-interview-prep/algorithms/implement-selection-sort.english.md index 773f93ff70..67d552b70e 100644 --- a/curriculum/challenges/english/08-coding-interview-prep/algorithms/implement-selection-sort.english.md +++ b/curriculum/challenges/english/08-coding-interview-prep/algorithms/implement-selection-sort.english.md @@ -29,7 +29,7 @@ tests: - text: selectionSort should return an array that is unchanged except for order. testString: assert.sameMembers(selectionSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]); - text: selectionSort should not use the built-in .sort() method. - testString: assert.strictEqual(code.search(/\.sort\(/), -1); + testString: assert(!code.match(/\.?[\s\S]*?sort/)); ```