Freecodecamp: Challenge: Confirm the Ending passes with .endsWith()

Created on 20 Aug 2016  路  4Comments  路  Source: freeCodeCamp/freeCodeCamp

function confirmEnding(str, target) {
  // "Never give up and good luck will find you."
  // -- Falcor
  return str.endsWith(target) // if I don't end with semi-colon it will pass.
}

confirmEnding("Bastian", "n");
first timers only help wanted

Most helpful comment

This line of code needs to be changed so the regex doesn't need the semi-colon or at least make it optional.

- !/\\.endsWith\\(.*?\\)\\s*?;/
+ !/\\.endsWith\\(.*?\\)\\s*?/

All 4 comments

I'm not sure this is a bug so much as a genuine solution for a user who finds it.

Edit: nvm, that's what I get for not actually visiting the challenge :)

Actually there is a test which asks the user not to use endsWith, and the regex is probably a bit too specific:
!/\\.endsWith\\(.*?\\)\\s*?;/.test(code)
when it would be sufficient to test only for .endsWith( to determine the method is used.
Right now with the semi-colon included in the regex, it's more like the test is saying "Don't use endsWith, at least not with the correct syntax anyway" 馃槃

This test is somewhat unique as I don't remember any other challenges which specify not to use a method, so I think it's okay to change this as a one-off revision.

This line of code needs to be changed so the regex doesn't need the semi-colon or at least make it optional.

- !/\\.endsWith\\(.*?\\)\\s*?;/
+ !/\\.endsWith\\(.*?\\)\\s*?/

I've implemented this one, please see pull request #10286

Was this page helpful?
0 / 5 - 0 ratings