question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Need more test for Escape Sequences in Strings.

See original GitHub issue

Challenge Escape Sequences in Strings has an issue. User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; AskTbORJ/5.15.9.29495; BRI/2; GWX:QUALIFIED; rv:11.0) like Gecko. Please describe how to reproduce this issue, and include links to screenshots if possible.

My code: var myStr = “FirstLine\n\Secondline\\rThirdLine”; // Change this line


var myStr = "FirstLine\n\\Secondline\\\rThirdLine"; // Change this line



Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

4reactions
billy-reillycommented, Jan 30, 2017

@raisedadead @systimotic Hi guys, I had a think about this - maybe it could be resolved by splitting the first test into two parts and then having a separate test for each special character which specifies where it should be placed:

  1. myStr should contain no spaces
  2. myStr should contain the strings FirstLine, SecondLine and ThirdLine (remember it’s case sensitive)
  3. FirstLine should be followed by the newline character \n
  4. SecondLine should be preceded by the backslash character \\
  5. SecondLine should be followed by the backslash character \\
  6. ThirdLine should be preceded by the carriage return character \r

I think the following code should do the job?

  1. assert(myStr.match(/\s/g).length == 0, 'message:
  2. assert((myStr.match(/FirstLine/g).length ==1 ) && (myStr.match(/SecondLine/g).length == 1) && (myStr.match(/ThirdLine/g).length == 1), 'message:
  3. assert(myStr.match(/FirstLine\n/g).length == 1, 'message:
  4. assert(myStr.match(/\\SecondLine/g).length == 1, 'message:
  5. assert(myStr.match(/SecondLine\\/g).length == 1, 'message:
  6. assert(myStr.match(/\rThirdLine/g).length == 1, 'message:

Could also have a test for the final correct answer to ensure that people aren’t adding in extra characters between the phrases checked above but that seems unnecessary to me.

I’m new to contributing but would be keen to submit a pull request for this if you think it’s correct?

1reaction
systimoticcommented, Feb 2, 2017

@billy-reilly Thanks a lot for taking a look at this! Your suggested changes look great! Since the live version, this challenge has changed a bit. You can check out the updates here on the beta: https://beta.freecodecamp.com/en/challenges/basic-javascript/escape-sequences-in-strings

A pull request would be awesome!

A couple of notes on your tests: The tab and newline character would both count as whitespace under the \s test. In this case, testing for a space character ( ) would probably be the best solution. You may already be aware of this, but for the actual test files, every backslash will have to escaped itself.

The tests for this challenge are here. If you run into any problems, feel free to go to our contributors chatroom.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Escape Sequences in Strings - Free Code Camp - YouTube
This is a basic JavaScript tutorial on how to escape sequences in strings. In this tutorial series, we go over the curriculum that...
Read more >
Escape Sequences in Strings, freeCodeCamp Basic Javascript
In this lesson we go over other escape sequences that we have access to such as newline, tab, and backspace (plus others).
Read more >
Escape Sequences in C - GeeksforGeeks
List of Escape Sequences. Some coding examples of escape characters ... Check if two same sub-sequences exist in a string or not.
Read more >
Process escape sequences in a string in Python
Most answers to this question have serious problems. There seems to be no standard way to honor escape sequences in Python without breaking...
Read more >
Escape Sequences in Strings SecondLine\\ - JavaScript
Here your code fails of course, becasue once browser reaches \S it finds it faulty, simple becasue there is no \S! Challenge needs...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found