Convert HTML Entities x

Tell us what’s happening:
When I attempt to test my function, the output I get appears identical. Copying the strings from the tests (as displayed in my browser; i obviously can’t see the actual test) and using a strict === comparison yields true for each example.
…but my tests are failing. Idk if I’m just too tired to see it, but I can’t locate my mistake(s).

Your code so far


function convertHTML(str) {
  const entityMap = {
    '&': '&​amp;',
    '<': '&​lt;',
    '>': '&​gt;',
    '"': '&​quot;',
    '\'': '&​apos;',
  }
  // &colon;&rpar; 
  
  return str
    .split('')
    .map((val) => 
      /([&<>"'\\])/.test(val) ? entityMap[val] : val
    )
    .join('')
    ;
}

const logAll = (...args) => { args.map((val) => { 
  console.log(val); 
  return val;
  })};
logAll( 
convertHTML("Dolce & Gabbana")
,convertHTML("Hamburgers < Pizza < Tacos")
,convertHTML("Sixty > twelve")
,convertHTML('Stuff in "quotation marks"')
,convertHTML("Schindler's List")
,convertHTML("<>")
,convertHTML("abc")
);
console.log(convertHTML("Dolce & Gabbana") === 'Dolce &​amp; Gabbana');

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.87 Safari/537.36.

Link to the challenge:

1 Like

… is the problem. If I remember aright, there’s an invisible character between the ampersand and the first letter of each. Type them manually, rather than copy-paste.

Retyping the entries in my entityMap did the trick. Thank you for the pointer.

1 Like