$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #104

What is the correct fix?

const versions = ['1.10.0', '1.9.0'];
versions.sort();
console.log(versions[0]);
  1. Compare each numeric part separately
  2. Compare with localeCompare directly
  3. Pad every version to a fixed length
  4. Reverse the array after sorting it
String order puts '1.10.0' before '1.9.0'; compare the numbers segment by segment.
Play Problem Solving ▸