Convert HTML Entities, should pass

This convoluted solution seems to work in Atom.
Why it doesn’t pass the challenge?


  function convertHTML(str) {
      let newStr = '';
      let regex = /&/g;
      let regex1 = /</g;
      let regex2 = />/g;
      let regex3 = /"/g;
      let regex4 = /'/g;
      let regex5 = /&|<|>|'|"/g;

      if (str.search(regex5)) {
        newStr = str;
      }

      let replaceEntities = entitie => {
        if (entitie === '&') {
          newStr = str.replace(regex, '&mp')
        } else if (entitie === '<') {
          newStr = str.replace(regex1, '&lt;')
        } else if (entitie === '>') {
          newStr = str.replace(regex2, '&gt;')
        } else if (entitie === '"') {
          newStr = str.replace(regex3, '&quot;')
        } else if (entitie === "'") {
          newStr = str.replace(regex4, '&apos;')
        }
      }

      for (var i = 0; i < str.length; i++) {
        replaceEntities(str[i])
      }
      return newStr;
    }

convertHTML('Stuff in "quotation marks"');

Your browser information:

User Agent is: Chrome.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/convert-html-entities/

When the for loop executes replaceEntities function, at str.length -1 position
it assigns to the function the last letter. So the fun checks if the last letter is a match.
But why is that a problem?
I tried to iterate until str.length-1, but still nothing.

I tried with switch but again nothing.
I looked at the solution. And there was exactly the same code.
The FCC code passed the test. Mine didn’t.
So I searched it piece by piece.
For an unknown, still to me, reason
this:

'&amp;'

would pass.
But mine (which is the same):

'&​amp;'

would not. This counts for all the other values too.
I then tried to change these values, to the above code.
Only one does not pass.

convertHTML("<>") should return &​lt;&​gt;.

While the others which include these tags, do pass.
The good thing is that I’ve learned again a lot today!

I will check everything you say. But first I need to tell you about these weird thing that
happend with that code.
I copied the code to a repository in github, and I got red dots in between the code!
You don’t see them down below. But if you try to backspace the entitie,
from ‘a’ to ‘&’ you need one extra hit to delete it.
Also in github I see them only on editing.
When I save it, it’s not visible.

arr[i] = '&​amp;'; 

Yes I did copy/paste. Good to know. I won’t copy paste again anything from the test results section. Thanks again for your help. I really appreciated it