API Docs for: 1.0.0
Show:

Sort Class

Utilities for sorting.

Item Index

Methods

Methods

compareAsNumber

(
  • a
  • b
)
Number static

The default behavior for sorting numbers. Provided for cases where one needs to compare object members.

Parameters:

  • a Number

    first number to compare

  • b Number

    second number to compare

Returns:

Number:

-1,0,+1 based on comparing the values

compareAsString

(
  • a
  • b
)
Number static

The default behavior for sorting strings. Provided for cases where one needs to compare object members.

Parameters:

  • a String

    first string to compare

  • b String

    second string to compare

Returns:

Number:

-1,0,+1 based on comparing the strings

compareAsStringNoCase

(
  • a
  • b
)
Number static

Parameters:

  • a String

    first string to compare

  • b String

    second string to compare

Returns:

Number:

-1,0,+1 based on comparing the strings when ignoring case

compareKey

(
  • f
  • key
)
Number static

Sort by an object member: sort(Y.bind(Y.Sort.compareKey, null, Y.Sort.compareAs*, key_or_path))

Key can be an array, to drill deep inside the objects, e.g., ['foo','bar','baz'] translates to a.foo.bar.baz

Parameters:

  • f Function

    comparator

  • key String | Array

    object key or path to the value which should be compared

Returns:

Number:

-1,0,+1 based on comparing the values

drill

(
  • key
  • a
  • b
)
Array static

Utility function for extracting the same value from both comparator arguments.

Parameters:

  • key Array

    path to element stored in both a and b

  • a Object

    first object to compare

  • b Object

    second object to compare

Returns:

Array:

values extracted from a and b

flip

(
  • f
)
Function static

Flip the sort order: sort(Y.Sort.flip(comparator))

Parameters:

  • f Function

    original comparator which takes 2 arguments

Returns:

Function:

new comparator that inverts the sort order