$ ./guess_the_languageProblem Solving — predict the output
Problem Solving — predict the output · medium · #61

What is the output?

console.log([3, 1, 20, 10].sort());
  1. [1, 10, 20, 3]
  2. [1, 3, 10, 20]
  3. [3, 1, 20, 10]
  4. [20, 10, 3, 1]
The default sort compares values as strings, so '10' sorts before '3'.
Play Problem Solving ▸