lib/SortByKey.js
function arraySortByKey(data, key, reverse) {
    data.sort((a, b) => {
        const aw = a[key] !== undefined ? (
            typeof a[key] === 'function' ?
            parseInt(a[key](), 10) :
            parseInt(a[key], 10)
        ) : 0;
        const bw = b[key] !== undefined ? (
            typeof b[key] === 'function' ?
            parseInt(b[key](), 10) :
            parseInt(b[key], 10)
        ) : 0;

        if (aw === bw) {
            return 0;
        }

        return reverse !== true && aw < bw ? -1 : 1;
    });
}
function arraySortByKey(data, key, reverse) {
    data.sort((a, b) => {
        const aw = a[key] !== undefined ? (
            typeof a[key] === 'function' ?
            parseInt(a[key](), 10) :
            parseInt(a[key], 10)
        ) : 0;
        const bw = b[key] !== undefined ? (
            typeof b[key] === 'function' ?
            parseInt(b[key](), 10) :
            parseInt(b[key], 10)
        ) : 0;

        if (aw === bw) {
            return 0;
        }

        return reverse !== true && aw < bw ? -1 : 1;
    });
}
function arraySortByKey ( data , key , reverse ) { data . sort ( ( a , b ) => { const aw = a [ key ] !== undefined ? ( typeof a [ key ] === 'function' ? parseInt ( a [ key ] ( ) , 10 ) : parseInt ( a [ key ] , 10 ) ) : 0 ; const bw = b [ key ] !== undefined ? ( typeof b [ key ] === 'function' ? parseInt ( b [ key ] ( ) , 10 ) : parseInt ( b [ key ] , 10 ) ) : 0 ; if ( aw === bw ) { return 0 ; } return reverse !== true && aw < bw ? - 1 : 1 ; } ) ; }
Sort an array by the provided key.

@param {Array} data The array to sort.
@param {string} key The key to use for sorting.
@param {boolean} [reverse=false] - Reverse the order.
Sort an array by the provided key .