import { sortBy } from "https://dotland.deno.dev/std@0.181.0/collections/sort_by.ts";
Returns all elements in the given collection, sorted by their result using the given selector. The selector function is called only once for each element.
Examples
Example 1
Example 1
import { sortBy } from "https://deno.land/std@0.181.0/collections/sort_by.ts";
import { assertEquals } from "https://deno.land/std@0.181.0/testing/asserts.ts";
const people = [
{ name: "Anna", age: 34 },
{ name: "Kim", age: 42 },
{ name: "John", age: 23 },
];
const sortedByAge = sortBy(people, (it) => it.age);
assertEquals(sortedByAge, [
{ name: "John", age: 23 },
{ name: "Anna", age: 34 },
{ name: "Kim", age: 42 },
]);