2016-05-20 09:14:05 +02:00
|
|
|
/**
|
|
|
|
* Sorting utilities
|
|
|
|
*/
|
2015-02-01 09:26:48 +01:00
|
|
|
|
2016-05-25 09:31:53 +02:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2016-05-20 09:14:05 +02:00
|
|
|
export const ignoreCase = (a, b) => {
|
|
|
|
let x = a.toLowerCase();
|
|
|
|
let y = b.toLowerCase();
|
|
|
|
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
|
|
|
|
}
|
|
|
|
|
2016-05-25 09:31:53 +02:00
|
|
|
/**
|
|
|
|
* Sorts passed numbers in a ascending manner
|
|
|
|
* @param {Number} First number
|
|
|
|
* @param {Number} Second number
|
|
|
|
* @param {Number} Negative, zero or positive number
|
|
|
|
*/
|
2016-05-20 09:14:05 +02:00
|
|
|
export const numSortAsc = (a, b) => (a - b);
|
|
|
|
|
2016-05-25 09:31:53 +02:00
|
|
|
/**
|
|
|
|
* Sorts passed numbers in a descending manner
|
|
|
|
* @param {Number} First number
|
|
|
|
* @param {Number} Second number
|
|
|
|
* @param {Number} Negative, zero or positive number
|
|
|
|
*/
|
2016-05-20 09:14:05 +02:00
|
|
|
export const numSortDesc = (a, b) => (b - a);
|