From 50f15886b85259d589df4b20b1052df7dae4a8d2 Mon Sep 17 00:00:00 2001 From: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> Date: Wed, 25 Mar 2020 05:28:17 -0700 Subject: [PATCH] fix(curriculum): Strip comments from user code for Use Destructuring Assignment to Extract Values from Objects challenge (#38213) * fix: strip user code to improve tests * fix: removed closing section tag messing up tests --- ...nt-to-extract-values-from-objects.english.md | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-extract-values-from-objects.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-extract-values-from-objects.english.md index d04a619427..3307bdce0e 100644 --- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-extract-values-from-objects.english.md +++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/es6/use-destructuring-assignment-to-extract-values-from-objects.english.md @@ -41,13 +41,14 @@ Replace the two assignments with an equivalent destructuring assignment. It shou ```yml tests: - text: You should remove the ES5 assignment syntax. - testString: assert(!code.match(/today = HIGH_TEMPERATURES\.today/g) && !code.match(/tomorrow = HIGH_TEMPERATURES\.tomorrow/g)) + testString: assert(!removeJSComments(code).match(/today\s*=\s*HIGH_TEMPERATURES\.(today|tomorrow)/g)) - text: You should use destructuring to create the today variable. - testString: assert(code.match(/(var|let|const)\s*{\s*(today[^}]*|[^,]*,\s*today)\s*}\s*=\s*HIGH_TEMPERATURES(;|\s+|\/\/)/g)); + testString: assert(removeJSComments(code).match(/(var|let|const)\s*{\s*(today[^}]*|[^,]*,\s*today)\s*}\s*=\s*HIGH_TEMPERATURES(;|\s+|\/\/)/g)); - text: You should use destructuring to create the tomorrow variable. - testString: assert(code.match(/(var|let|const)\s*{\s*(tomorrow[^}]*|[^,]*,\s*tomorrow)\s*}\s*=\s*HIGH_TEMPERATURES(;|\s+|\/\/)/g)); + testString: assert(removeJSComments(code).match(/(var|let|const)\s*{\s*(tomorrow[^}]*|[^,]*,\s*tomorrow)\s*}\s*=\s*HIGH_TEMPERATURES(;|\s+|\/\/)/g)); - text: today should be equal to 77 and tomorrow should be equal to 80. testString: assert(today === 77 && tomorrow === 80); + ``` @@ -72,6 +73,16 @@ const tomorrow = HIGH_TEMPERATURES.tomorrow; ``` + +### After Test +
+ +```js +const removeJSComments = str => str.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, ''); +``` + +
+ ## Solution