JavaScript bootcamp · Lab 48

Bubble sort

mediumArrays15 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; print them ascending using bubble sort (or any sort).

Input. Space-separated integers.

Output. Sorted ascending.

Examples

Example 1
Input
3 1 2
Output
1 2 3
Hint
  1. nums.sort((a,b)=>a-b) is fine for this lab.
Show correct code

Peek only after you have tried. You can still Check your own version.

const nums = readLine().trim().split(/\s+/).map(Number);
console.log(nums.sort((a, b) => a - b).join(' '));
main.jsconsole.log · readLine() · Ctrl + Enter
ResultIdle
Run to see output. Check grades the tests.