import { orderBy } from "https://deno.land/x/ayonli_jsext@v0.9.72/array/index.ts";
Orders the items of the array according to the given callback function.
Examples
Example 1
Example 1
import { orderBy } from "@ayonli/jsext/array";
const arr = [
{ id: 1, name: "foo" },
{ id: 2, name: "bar" },
{ id: 3, name: "baz" },
{ id: 4, name: "qux" },
];
console.log(orderBy(arr, item => item.name));
// [
// { id: 2, name: "bar" },
// { id: 3, name: "baz" },
// { id: 1, name: "foo" },
// { id: 4, name: "qux" }
// ]
console.log(orderBy(arr, item => item.id, "desc"));
// [
// { id: 4, name: "qux" },
// { id: 3, name: "baz" },
// { id: 2, name: "bar" },
// { id: 1, name: "foo" }
// ]
Orders the items of the array according to the specified comparable key
(whose value must either be a numeric or string).