Code Explainers

Code explainers tagged #comparators

typescript
type SortDirection = "asc" | "desc";
 
interface SortKey<T> {
  selector: (row: T) => string | number | Date | null | undefined;

Multi-column sorting in TypeScript

generics comparators sorting
Intermediate 6 steps
go
type Employee struct {
	Department string
	LastName   string
	FirstName  string

Multi-key sorting in Go

sorting comparators tie-breaking
Intermediate 6 steps
javascript
function makeTableSorter(rows) {
  const state = { key: null, dir: 1 };
 
  const compareBy = (key) => (a, b) => {

Building a stateful table sorter in JavaScript

closures stable-sort comparators
Intermediate 7 steps