Two to One

JavaScript

function longest(s1, s2) {
  let uniqueString = "";
  const uniqueLetter = (letter) => !uniqueString.includes(letter);

  function includeString(str) {
    for (let i = 0; i < str.length; i++) {
      const currentChar = str.charAt(i);
      if (uniqueLetter(currentChar)) {
        uniqueString += currentChar;
      }
    }
  }

  includeString(s1);
  includeString(s2);

  return sortString(uniqueString);
}

function sortString(str) {
  const arr = str.split('');
  const sorted = arr.sort();
  return sorted.join('');
}

Tags

  1. javascript (Private)
  2. 7-kyu (Private)
  3. codewars (Private)
  4. answer (Private)