Skip to main content

compare-numeric-value ()

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

Signatures

compare-numeric-value ( $first-pair, $second-pair [, $center] )

Compares two key/value pairs’ values as numbers in ascending order. All non-numeric items are shifted right.

Details

Parameters

$first-pair
The first key/value pair for the comparison.
Type
*
$second-pair
The second key/value pair for the comparison.
Type
*
$center
The value indicating the center (zero) position between positive and negative values.
Type
Number
Default
0

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-numeric-value ()

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-numeric-value(b 8em, f 10mm);
// -2

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

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