Hey Shantanu Borgohain, Thanks so much for reading and responding. That’s a fantastic catch, it shows me that I have a cognitive bias about how it “should” work in JavaScript. You’re exactly right, and I’ve fixed it: the comparison function returns a negative value if the second item is bigger, or a positive value if the second item is smaller. Of course, it’s just basic arithmetic: a-b.

Thanks again, I really truly appreciate it.

PS You have a fantastic name! I love it! Have a great one 🤩

Written by

🤓 The physical therapist who writes JavaScript 💪 Web Developer 😎 Mentor 🧠 DPT 😄 SEO Expert 😁 React 😆 Jamstack 🗯️ Ask me anything 👉 DoctorDerek.com 👈

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store