Read the question, write JavaScript on the right, then Run or Check.
QuestionHint and solution stay closed until you open them
Read two lines of integers. Print the sorted intersection, space-separated.
Input. Two lines of integers.
Output. Common values sorted.
Examples
Input
1 2 3 4 3 4 5
Output
3 4
Hint
- Use Set; filter a by has; sort.
Show correct code
Peek only after you have tried. You can still Check your own version.
const a = readLine().trim().split(/\s+/).map(Number);
const b = new Set(readLine().trim().split(/\s+/).map(Number));
console.log(a.filter((x) => b.has(x)).sort((x, y) => x - y).join(' '));
main.jsconsole.log · readLine() · Ctrl + Enter
ResultIdle
Run to see output. Check grades the tests.