Randell Dawson 05f73ca409 fix(curriculum): Convert blockquote elements to triple backtick syntax for JavaScript Algorithms and Data Structures (#35992)
* fix: convert js algorithms and data structures

* fix: revert some blocks back to blockquote

* fix: reverted comparison code block to blockquotes

* fix: change js to json

Co-Authored-By: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>

* fix: convert various section to triple backticks

* fix: Make the formatting consistent for comparisons
2019-05-17 08:20:30 -05:00

2.1 KiB

id, title, challengeType
id title challengeType
587d7db7367417b2b2512b9e Match Ending String Patterns 1

Description

In the last challenge, you learned to use the caret character to search for patterns at the beginning of strings. There is also a way to search for patterns at the end of strings. You can search the end of strings using the dollar sign character $ at the end of the regex.
let theEnding = "This is a never ending story";
let storyRegex = /story$/;
storyRegex.test(theEnding);
// Returns true
let noEnding = "Sometimes a story will have to end";
storyRegex.test(noEnding);
// Returns false

Instructions

Use the anchor character ($) to match the string "caboose" at the end of the string caboose.

Tests

tests:
  - text: You should search for <code>"caboose"</code> with the dollar sign <code>$</code> anchor in your regex.
    testString: assert(lastRegex.source == "caboose$", 'You should search for <code>"caboose"</code> with the dollar sign <code>$</code> anchor in your regex.');
  - text: Your regex should not use any flags.
    testString: assert(lastRegex.flags == "", 'Your regex should not use any flags.');
  - text: You should match <code>"caboose"</code> at the end of the string <code>"The last car on a train is the caboose"</code>
    testString: assert(lastRegex.test("The last car on a train is the caboose"), 'You should match <code>"caboose"</code> at the end of the string <code>"The last car on a train is the caboose"</code>');

Challenge Seed

let caboose = "The last car on a train is the caboose";
let lastRegex = /change/; // Change this line
let result = lastRegex.test(caboose);

Solution

let caboose = "The last car on a train is the caboose";
let lastRegex = /caboose$/; // Change this line
let result = lastRegex.test(caboose);