Skip to main content
variable orderBy
import { orderBy } from "https://deno.land/x/30_seconds_of_typescript@v1.0.1/util.ts";

Returns a sorted array of objects ordered by properties and orders.

Uses Array.prototype.sort(), Array.prototype.reduce() on the props array with a default value of 0, use array destructuring to swap the properties position depending on the order passed. If no orders array is passed it sort by 'asc' by default.

type

<T = AnyObject>(
arr: T[],
props: (keyof T)[],
orders?: ("asc" | "desc")[],
) => unknown