liveBook · Manning

Sorting algorithm

As explained in Build a Website with ChatGPT

Sorting is the operation of arranging data records or values according to an ordering criterion.

Sorting arranges displayed records according to a selected field. Text fields are ordered alphabetically, while number fields are ordered numerically. section 13.4.3

A web page typically handles sorting in three steps:

  • Offer a drop-down list containing the sortable fields. section 13.4.3
  • Detect the user’s selection with JavaScript and sort the records by that field. section 13.4.3
  • Redisplay the reordered records in the page’s article element. section 13.4.3
A drop-down list with the ID "Sort" and the values: "Sort by Department" and "Sort by Title".

Use a Sort drop-down with options such as “Sort by Department” and “Sort by Title.” section 13.4.3

Course catalog

A course catalog can let users sort records by Department or Title. JavaScript fetches the JSON data, orders it using the chosen field, and writes the results into the page. section 13.4.3 section 13.5

How Build a Website with ChatGPT covers it

How deep it goes
Explains the control-to-redisplay workflow but stops short of algorithm internals or detailed sorting code.
Examples
Uses a course catalog whose records sort by Department or Title through a drop-down list.
What it assumes
Assumes records contain fields suitable for ordering and introduces the required selector, event handling, and redisplay flow.
What you can do after
Apply it via JavaScript by connecting a sort selector to reordered JSON records and a refreshed article element.
How it connects
Connects sorting with JavaScript, JSON, filtering, searching, drop-down lists, and dynamic page rendering.

Also explained in

Compare how 18 books explain sorting algorithm →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Website with ChatGPT. The section links point to the parts of the book it draws on.