(a, b)
| 2 | |
| 3 | const numeric = /^[0-9]+$/ |
| 4 | const compareIdentifiers = (a, b) => { |
| 5 | if (typeof a === 'number' && typeof b === 'number') { |
| 6 | return a === b ? 0 : a < b ? -1 : 1 |
| 7 | } |
| 8 | |
| 9 | const anum = numeric.test(a) |
| 10 | const bnum = numeric.test(b) |
| 11 | |
| 12 | if (anum && bnum) { |
| 13 | a = +a |
| 14 | b = +b |
| 15 | } |
| 16 | |
| 17 | return a === b ? 0 |
| 18 | : (anum && !bnum) ? -1 |
| 19 | : (bnum && !anum) ? 1 |
| 20 | : a < b ? -1 |
| 21 | : 1 |
| 22 | } |
| 23 | |
| 24 | const rcompareIdentifiers = (a, b) => compareIdentifiers(b, a) |
| 25 |
no test coverage detected