$ ./guess_the_languageProblem Solving — predict the output
Problem Solving — predict the output · hard · #42

What is the output?

const xs: number[] = [1, 2, 10, 3];
console.log(xs.sort());
  1. [1, 2, 3, 10]
  2. [10, 3, 2, 1]
  3. [1, 2, 10, 3]
  4. [1, 10, 2, 3]
Default sort compares strings, so "10" precedes "2".
Play Problem Solving ▸