Read the question, write JavaScript on the right, then Run or Check.
QuestionHint and solution stay closed until you open them
Read a line of integers. Log the even ones space-separated (same order).
Input. Space-separated integers.
Output. Evens space-separated.
Examples
Input
1 2 3 4 5
Output
2 4
Input
1 3 5
Output
Hint
- filter(x => x % 2 === 0).join(' ')
Show correct code
Peek only after you have tried. You can still Check your own version.
const nums = readLine().trim().split(/\s+/).filter(Boolean).map(Number);
console.log(nums.filter((x) => x % 2 === 0).join(' '));
main.jsconsole.log · readLine() · Ctrl + Enter
ResultIdle
Run to see output. Check grades the tests.