Last change
on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
409 bytes
|
Line | |
---|
1 | const numeric = /^[0-9]+$/
|
---|
2 | const compareIdentifiers = (a, b) => {
|
---|
3 | const anum = numeric.test(a)
|
---|
4 | const bnum = numeric.test(b)
|
---|
5 |
|
---|
6 | if (anum && bnum) {
|
---|
7 | a = +a
|
---|
8 | b = +b
|
---|
9 | }
|
---|
10 |
|
---|
11 | return a === b ? 0
|
---|
12 | : (anum && !bnum) ? -1
|
---|
13 | : (bnum && !anum) ? 1
|
---|
14 | : a < b ? -1
|
---|
15 | : 1
|
---|
16 | }
|
---|
17 |
|
---|
18 | const rcompareIdentifiers = (a, b) => compareIdentifiers(b, a)
|
---|
19 |
|
---|
20 | module.exports = {
|
---|
21 | compareIdentifiers,
|
---|
22 | rcompareIdentifiers
|
---|
23 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.