You cannot treat any arbitrary input as a regular expression, because this way you can create malformed regex.
For example, if the input is "(" and you want to turn it into a regex in a naive way, you end up with regular expression of /(/g, which is not a valid regex pattern.
This task does not even need regex, regex based slution for this task is probably more complicated than even necessary.
hey guys. i am solving with js, and when i want to add ")" to string, it raises an error SyntaxError: Invalid regular expression. It works OK with letters, but not with "(" or ")". can anyone help?
ok, thank you mate, i'll do it another way.
You cannot treat any arbitrary input as a regular expression, because this way you can create malformed regex.
For example, if the input is
"("
and you want to turn it into a regex in a naive way, you end up with regular expression of/(/g
, which is not a valid regex pattern.This task does not even need regex, regex based slution for this task is probably more complicated than even necessary.
hey guys. i am solving with js, and when i want to add ")" to string, it raises an error
SyntaxError: Invalid regular expression
. It works OK with letters, but not with "(" or ")". can anyone help?Thanks for the reply!
That's because your solution has a bug. It does not work for a following test case either:
assert.strictEqual(duplicateEncode("aA"),"))");
Hi!
It works in my IDE but not here. The only test that fail is: "Supralapsarian"
https://www.codewars.com/kata/546f922b54af40e1e90001da/discuss#632895c124dbb526e9c5af49
In IDE works fine, but in codewars replaceAll is not a function :/
Read this: https://docs.codewars.com/training/troubleshooting#.print-vs-return
Please mark your post as having spoiler content next time and use markdown formatting, see how to post your code in the docs too.
This comment is hidden because it contains spoiler information about the solution
Thank you a lot for the reply
The error message is this:
And that's because
replaceAll
requires Node v15 or higher: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll#browser_compatibilityHi!
My solution works in my ide, but not here.
throw this "TypeError: .......... is not a function"