Explore programmers.im
AI literacyprogrammers.im

Home · By hand vs AI

Side by side

By hand vs AI

One snippet was written carefully, with a compare function from MDN. The other is the sort of shortcut a coding assistant might offer. Which would you run if you needed numeric order?

By hand

A sample assistant reply

Which snippet would you run?

You need the scores in numeric order, smallest to largest. Which snippet should you use?

To sort numbers in ascending order, MDN's memory aid is the compare function (a, b) => a - b. A compareNumbers helper that returns a - b does the same. MDN: Array.sort() MDN's own example shows that [1, 30, 4, 21, 100000].sort(), with no compare function, comes out as [1, 100000, 21, 30, 4], not numeric order. MDN: Array.sort()

Sample assistant replies

The "assistant" replies on this site were written by us for the lesson. They are not live results from an AI tool, and nothing you type is sent to one. That way every visitor sees the same lesson.

The point is not that every assistant reply is wrong. It is that a reply is a first draft: read it, test it, and check it.