Comments

Bryan Guilasa day ago

It's a bit long but here is my solution using hash tables.

const solve = (strOne, strTwo) => {
    let shorter = strOne.length < strTwo.length ? strOne : strTwo;
    let longer = strOne.length > strTwo.length ? strOne : strTwo;
    const hash1 = {};
    const hash2 = {};
    for (let char of shorter) {
        hash1[char] ? hash1[char]++ : hash1[char] = 1;
    }
    for (let char of longer) {
        hash2[char] ? hash2[char]++ : hash2[char] = 1;
    }
    for (let key in hash2) {
        if (hash2[key] !== hash1[key]) return key;
    }
  return true;
};

Coordinator proactive3 months ago

A simple, no Array functions, single round iteration approach:

const solve = (strOne, strTwo) => {
  let shorter = strOne.length < strTwo.length ? strOne : strTwo;
  let longer = strOne.length > strTwo.length ? strOne : strTwo;
  for (let i = 0; i < shorter.length; i++) {
    if (shorter[i] !== longer[i]) return longer[i];
  }
};

Ameliorated Tugrik3 months ago

If there is someone who's looking for a solution in one line - JUST LEARN REGEX! It took me a day to get used to the syntax. Here's a website I learnt **www.regexone.com ** I'd also recommend to watch **Mastering Regular Expressions in JavaScript ** by Steven Hancock

const solve = (s1, s2) => (s1 + s2).split('').sort().join('').replace(/(\w)\1/g, '')

Abdelhamid Ismaila year ago

const solve = (strOne, strTwo) => {
  
  return strOne.length > strTwo.length ? strOne.split('').find((char,index) => strTwo.split('')[index] !== char) : strTwo.split('').find((char,index) => strOne.split('')[index] !== char)
};

Abdelhamid Ismaila year ago

Same code but in a better format

const solve = (strOne, strTwo) => {
  return strOne.length > strTwo.length
    ? strOne.split("").find((char, index) => strTwo.split("")[index] !== char)
    : strTwo.split("").find((char, index) => strOne.split("")[index] !== char);
};

zunair jarrala year ago

Below codes works super anyone can suggest compact one i mean two liner or 3 liner

const solve = (strOne, strTwo) => { let strOne1; let strTwo2; if (strOne.length > strTwo.length) { strTwo2 = strOne; strOne1 = strTwo; } else { strTwo2 = strTwo; strOne1 = strOne; } let a = [...strOne1]; let b = [...strTwo2]; let c = [...a.entries()]; let d = [...b.entries()]; let e = c.join('|'); let f = d.join('|'); let g = e.split('|'); let h = f.split('|'); return h.find((word) => !g.includes(word)).replace(/[0-9,]/gi,''); };

Abdelhamid Ismaila year ago

Here it is a long one liner :D

const solve = (strOne, strTwo) => {
  
  return strOne.length > strTwo.length ? strOne.split('').find((char,index) => strTwo.split('')[index] !== char) : strTwo.split('').find((char,index) => strOne.split('')[index] !== char)
};

paymenta year ago

const solve = (strOne, strTwo) => { let [ arrWithRandomLetter, normal ] = strOne.length > strTwo.length ? [ strOne.split(''), strTwo.split('') ] : [ strTwo.split(''), strOne.split('') ];

normal.forEach((letter) => {
  const index = arrWithRandomLetter.findIndex(e => e === letter);
  if(index !== -1) arrWithRandomLetter[index] = '';
});

return arrWithRandomLetter.join('');

};

David Ko2 years ago

this problem does not have a clear question or examples