JavaScript bootcamp · Lab 31

Reverse the list

easyArrays8 minLesson: Arrays

Read the question, write JavaScript on the right, then Run or Check.

QuestionHint and solution stay closed until you open them

Read integers and print them reversed, space-separated.

Input. Space-separated integers.

Output. Reversed list.

Examples

Example 1
Input
1 2 3
Output
3 2 1
Hint
  1. [...nums].reverse().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);
console.log([...nums].reverse().join(' '));
main.jsconsole.log · readLine() · Ctrl + Enter
ResultIdle
Run to see output. Check grades the tests.