1 function compareValues(key, order = 'asc') {
2 return function innerSort(a, b) {
3 if (!a.hasOwnProperty(key) || !b.hasOwnProperty(key)) {
4 // property doesn't exist on either object
5 return 0;
6 }
7
8 const varA = (typeof a[key] === 'string')
9 ? a[key].toUpperCase() : a[key];
10 const varB = (typeof b[key] === 'string')
11 ? b[key].toUpperCase() : b[key];
12
13 let comparison = 0;
14 if (varA > varB) {
15 comparison = 1;
16 } else if (varA < varB) {
17 comparison = -1;
18 }
19 return (
20 (order === 'desc') ? (comparison * -1) : comparison
21 );
22 };
23}