1
0
Fork 0
mirror of https://github.com/koalyptus/TableFilter.git synced 2024-05-17 05:46:39 +02:00
TableFilter/src/sort.js
2016-05-25 17:31:53 +10:00

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