Is this wrong? Should I not have done this?

Tell us what’s happening:
I ran through two different methods on this, for loop with the string and splitting and iterating over the array… then I realize the function i was using in my other solutions could just do everything… so i did that. Is there a practical reason you wouldn’t want to do this?

Trying not to post a working solution… not sure how to hide that yet.
Your code so far

return str.replaceAll(args) //repeated for each character
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36

Challenge: Convert HTML Entities

Link to the challenge:

I can’t quite figure out what you’re asking. Can you be more specific and share the code that you’re talking about?

I didn’t want to share the whole thing, since it was a working solution…


function convertHTML(str) {
  return str.replaceAll("\&" , "\&amp\;")
            .replaceAll("\<" , "\&lt\;")
            .replaceAll("\>" , "\&gt\;")
            .replaceAll("\"" , "\&quot\;")
            .replaceAll("\'" , "\&apos\;");

convertHTML("Dolce & Gabbana");

Is the question whether there’s anything wrong with chaining a whole bunch of replaceAll calls like that?

Yes. I had more complex solutions using loops, etc. and this just popped out at me as a possibility.

There’s nothing wrong with chaining methods. Sometimes if you find yourself copy-pasting the same thing (with variations) that is an indication that there might be a more concise way to do, so it’s always something to give thought to.


This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.