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('');
}
- javascript (Private)
- 7-kyu (Private)
- codewars (Private)
- answer (Private)