Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/dnx/comparisons/compareBy.ts>default

Fluent modular JavaScript utility library.
Go to Latest
function default
import { default } from "https://deno.land/x/dnx@0.0.4/comparisons/compareBy.ts";

Returns a Collator using the specified selectors.

Each selector is called in order until the selected values differ in order in which case the comparison of those values is returned.

A selector can be a property key string | number | symbol or a function (value: T) => Collatable.

const persons = [
  { name: "Frank", age: 22 },
  { name: "Elizabeth", age: 42 },
  { name: "Bob", age: 34 },
  { name: "Elizabeth", age: 21 },
];

persons[sortedWith](compareBy("name", "age"));
// => [
//     { name: "Bob", age: 34 },
//     { name: "Elizabeth", age: 21 },
//     { name: "Elizabeth", age: 42 },
//     { name: "Frank", age: 22 }
//   ]

Parameters

...selectors: Selectors<T>