Skip to content

#274 Simple Letters

Adam Kubiś edited this page Oct 28, 2026 · 1 revision

274 Simple Letters

Create a function that takes two lowercase strings str1 and str2 of letters from a to z and returns the sorted and longest string containing distinct letters.

Current source and tests | Catalog | Testing and tooling

Run this solution

From the cloned repository root, after installing dependencies:

node "Edabit/274 Simple Letters.js"

Assertions are kept alongside the implementation and throw on failure. A successful run exits with code 0. Run every exercise with npm test or both lint and tests with npm run check.

Current implementation and tests

This is the complete executable file, including its imports and inline test cases. Run it from the repository, not as an isolated file copied out of the wiki. Line endings and trailing whitespace are normalized; executable tokens are unchanged.

//Create a function that takes two lowercase strings str1 and str2 of letters from a to z and returns the sorted and longest string containing distinct letters.
function longestString(str1, str2) {
    return [...new Set(str1 + str2)].sort((left, right) => left.localeCompare(right, 'en')).join('');
}
import { assertEquals } from '../testHelper.js';
assertEquals(longestString("mubashir", "edabit"), "abdehimrstu")
assertEquals(longestString("pakistan", "airforce"), "acefiknoprst")
assertEquals(longestString("", "e"), "e")
assertEquals(longestString("", ""), "")
assertEquals(longestString("noooo", "yesssss"), "enosy")
assertEquals(longestString("aretheyhere", "yestheyarehere"), "aehrsty")
assertEquals(longestString("loopingisfunbutdangerous", "lessdangerousthancoding"), "abcdefghilnoprstu")
assertEquals(longestString("inmanylanguages", "theresapairoffunctions"), "acefghilmnoprstuy")
assertEquals(longestString("lordsofthefallen", "gamekult"), "adefghklmnorstu")

Clone this wiki locally