| Conditions | 7 |
| Total Lines | 30 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | module.exports = function multisort(original, key, direction) { |
||
| 2 | let moveDirection = 1; |
||
| 3 | |||
| 4 | if (direction === 'desc') { |
||
| 5 | moveDirection = -1; |
||
| 6 | } |
||
| 7 | |||
| 8 | return original.sort((a, b) => { |
||
| 9 | let nameA = a[key]; |
||
| 10 | let nameB = b[key]; |
||
| 11 | |||
| 12 | if (typeof nameA === 'string') { |
||
| 13 | nameA = nameA.toUpperCase(); |
||
| 14 | } |
||
| 15 | |||
| 16 | if (typeof nameB === 'string') { |
||
| 17 | nameB = nameB.toUpperCase(); |
||
| 18 | } |
||
| 19 | |||
| 20 | if (nameA < nameB) { |
||
| 21 | return -1 * moveDirection; |
||
| 22 | } |
||
| 23 | |||
| 24 | if (nameA > nameB) { |
||
| 25 | return 1 * moveDirection; |
||
| 26 | } |
||
| 27 | |||
| 28 | return 0; |
||
| 29 | }); |
||
| 30 | }; |
||
| 31 |