DEV Community

Discussion on: Daily Challenge #243 - Redacted!

Collapse
 
mellen profile image
Matt Ellen

A javascript way. Although I think this could be done with regex...

function check(doc1, doc2)
{
  let docCheck = [...doc1].reduce((acc, cha, i) => 
  {
    if(cha.toLowerCase() === 'x')
    {
      acc += doc2[i];
    }
    else
    {
      acc += cha;
    }
    return acc;
  }, '');

  return docCheck === doc2;
}
Collapse
 
dimaip profile image
Dmitri Pisarev 🇷🇺

This one can be slightly optimised to return early on failure and not go through the whole string:

const isSame = (a, b) => a.split('').every((char, index) => char === 'X' || char === b[index])