Read the question, write TypeScript on the right, then Run or Check.
QuestionHint and solution stay closed until you open them
Read words; print them sorted by length (stable), space-separated.
Input. Space-separated words.
Output. Words by length.
Examples
Input
cat elephant a dog
Output
a cat dog elephant
Hint
- [...words].sort((a,b) => a.length - b.length)
Show correct code
Peek only after you have tried. You can still Check your own version.
const words = readLine().trim().split(/\s+/);
console.log([...words].sort((a, b) => a.length - b.length).join(' '));
main.tstsc · readLine() · Ctrl + Enter
ResultIdle
Run to see output. Check grades the tests.