Code screenshot

Javascript中伏記:sorting default behavior

const nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]; nums.sort(); // [1, 10, 11, 12, 2, 3, 4, 5, 6, 7, 8, 9] 🤯 nums.sort((a, b) => a - b); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] 😌

July 5, 2022 · 1 min · 50 words · Me