Skip to main content

compare-key-desc ()

Read more on comparison logic for a detailed explanation on sorting methods.

Signatures

compare-key-desc ( $first-pair, $second-pair )

Compares two key/value pairs’ keys by converting them to strings, then comparing the value’s sequences of UTF-16 code units values in descending order. All null items are shifted left.

Details

Parameters

$first-pair
The first key/value pair for the comparison.
Type
*
$second-pair
The second key/value pair for the comparison.
Type
*

Return Value

Number
A positive number when the first given value is greater than the second given value, or a negative number when the second given value is greater than the first given value; otherwise, zero.
compare-key-desc ()

Returns a function reference to this string comparison method to be used by the sort function.

Details

Return Value

Function
A reference to this string comparison method.

Example

@use '@sass-fairy/list';
@use '@sass-fairy/map';

// 1. As a call
@debug map.compare-key-desc(b 8em, f 10mm);
// 4

// 2. As a reference
$map: (b: 8em, f: 10mm, d: a, a: 3, c: 1cm, e: 2mm);

@debug list.sort($map, map.compare-key-desc());
// f 10mm, e 2mm, d a, c 1cm, b 8em, a 3