mirror of
https://github.com/koalyptus/TableFilter.git
synced 2024-05-23 08:42:18 +02:00
34 lines
930 B
JavaScript
34 lines
930 B
JavaScript
/**
|
|
* Sorting utilities
|
|
*/
|
|
|
|
/**
|
|
* Case insensitive compare function for passed strings
|
|
* @param {String} First string
|
|
* @param {String} Second string
|
|
* @return {Number} -1 if first string lower than second one
|
|
* 0 if first string same order as second one
|
|
* 1 if first string greater than second one
|
|
*/
|
|
export const ignoreCase = (a, b) => {
|
|
let x = a.toLowerCase();
|
|
let y = b.toLowerCase();
|
|
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
|
|
}
|
|
|
|
/**
|
|
* Sorts passed numbers in a ascending manner
|
|
* @param {Number} First number
|
|
* @param {Number} Second number
|
|
* @param {Number} Negative, zero or positive number
|
|
*/
|
|
export const numSortAsc = (a, b) => (a - b);
|
|
|
|
/**
|
|
* Sorts passed numbers in a descending manner
|
|
* @param {Number} First number
|
|
* @param {Number} Second number
|
|
* @param {Number} Negative, zero or positive number
|
|
*/
|
|
export const numSortDesc = (a, b) => (b - a);
|