Deviopath › TypeScript

Generic sortBy

Medium · Generics

Write sortBy<T, K extends keyof T>(items: T[], key: K, direction: "asc" | "desc" = "asc"): T[].

Return a new sorted array (do not change the input). Compare values with < and >, so it works for numbers and strings. Items with equal values keep their original order.

Next: Shape Area