Read the question, write JavaScript on the right, then Run or Check.
QuestionHint and solution stay closed until you open them
Read two words (one per line) and log yes if they are anagrams, otherwise no.
Anagrams use exactly the same letters rearranged. Compare case-insensitively.
Input. Two lines, each a word.
Output. yes or no (lowercase).
Examples
Input
listen silent
Output
yes
Input
hello world
Output
no
Hint
- Sort the letters of each word — anagrams become identical strings.
- [...word].sort().join("") gives a canonical form.
Show correct code
Peek only after you have tried. You can still Check your own version.
const a = [...readLine().trim().toLowerCase()].sort().join("");
const b = [...readLine().trim().toLowerCase()].sort().join("");
console.log(a === b ? "yes" : "no");
main.jsconsole.log · readLine() · Ctrl + Enter
ResultIdle
Run to see output. Check grades the tests.