UNPKG

figmacoder

Version:

FIGMACODER is a npm library for generating an express application

14 lines (11 loc) 474 B
module.exports = (key, order = 'asc') => { return function sort(a, b) { if (!a.hasOwnProperty(key) || !b.hasOwnProperty(key)) return 0; const x = (typeof a[key] === 'string') ? a[key].toUpperCase() : a[key]; const y = (typeof b[key] === 'string') ? b[key].toUpperCase() : b[key]; let comparison = 0; if (x > y) comparison = 1; else if (x < y) comparison = -1; return ((order === 'desc') ? (comparison * -1) : comparison); }; }