Skip to main content

compare-string ()

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

Signatures

compare-string ( $first-item, $second-item )

Compares two list items by converting them to strings, then comparing the value’s sequences of UTF-16 code units values in ascending order. All null items are shifted right.

Details

Parameters

$first-item
The first item for the comparison.
Type
*
$second-item
The second item 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-string ()

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';

// 1. As a call
@debug list.compare-string('x', 'm');
// 11

// 2. As a reference
$list: 'x' 'm' 'b' 't';

@debug list.sort($list, list.compare-string());
// 'b' 'm' 't' 'x'