1
- [ js-compare] ( http://aureooms.github.io/js-compare )
1
+ [ @ aureooms/ js-compare] ( http://aureooms.github.io/js-compare )
2
2
==
3
3
4
- Comparison code bricks for JavaScript.
4
+ Comparison library for JavaScript.
5
+ See [ docs] ( https://aureooms.github.io/js-compare/index.html ) .
5
6
6
7
``` js
7
8
let compare = reverse ( lexicographical ( increasing ) ) ;
@@ -23,149 +24,6 @@ compare( [ 1 , 1 ] , [ 1 , 2 ] ) > 0 ; // true
23
24
[ ![ Documentation] ( http://aureooms.github.io/js-compare//badge.svg )] ( http://aureooms.github.io/js-compare//source.html )
24
25
[ ![ Package size] ( https://img.shields.io/bundlephobia/minzip/@aureooms/js-compare )] ( https://bundlephobia.com/result?p=@aureooms/js-compare )
25
26
26
- Can be managed through [ jspm] ( https://github.com/jspm/jspm-cli ) ,
27
- [ duo] ( https://github.com/duojs/duo ) ,
28
- [ component] ( https://github.com/componentjs/component ) ,
29
- [ bower] ( https://github.com/bower/bower ) ,
30
- [ ender] ( https://github.com/ender-js/Ender ) ,
31
- [ jam] ( https://github.com/caolan/jam ) ,
32
- [ spm] ( https://github.com/spmjs/spm ) ,
33
- and [ npm] ( https://github.com/npm/npm ) .
34
-
35
- ## Install
36
-
37
- ### jspm
38
- ``` terminal
39
- jspm install github:aureooms/js-compare
40
- # or
41
- jspm install npm:@aureooms/js-compare
42
- ```
43
- ### duo
44
- No install step needed for duo!
45
-
46
- ### component
47
- ``` terminal
48
- component install aureooms/js-compare
49
- ```
50
-
51
- ### bower
52
- ``` terminal
53
- bower install @aureooms/js-compare
54
- ```
55
-
56
- ### ender
57
- ``` terminal
58
- ender add @aureooms/js-compare
59
- ```
60
-
61
- ### jam
62
- ``` terminal
63
- jam install @aureooms/js-compare
64
- ```
65
-
66
- ### spm
67
- ``` terminal
68
- spm install @aureooms/js-compare --save
69
- ```
70
-
71
- ### npm
72
- ``` terminal
73
- npm install @aureooms/js-compare --save
74
- ```
75
-
76
- ## Require
77
- ### jspm
78
- ``` js
79
- let compare = require ( " github:aureooms/js-compare" ) ;
80
- // or
81
- import compare from ' @aureooms/js-compare' ;
82
- ```
83
- ### duo
84
- ``` js
85
- let compare = require ( " aureooms/js-compare" ) ;
86
- ```
87
-
88
- ### component, ender, spm, npm
89
- ``` js
90
- let compare = require ( " @aureooms/js-compare" ) ;
91
- ```
92
-
93
- ### bower
94
- The script tag exposes the global variable ` compare ` .
95
- ``` html
96
- <script src =" bower_components/@aureooms/js-compare/js/dist/compare.min.js" ></script >
97
- ```
98
- Alternatively, you can use any tool mentioned [ here] ( http://bower.io/docs/tools/ ) .
99
-
100
- ### jam
101
- ``` js
102
- require ( [ " @aureooms/js-compare" ] , function ( compare ) { ... } ) ;
103
- ```
104
-
105
- ## Use
106
-
107
- ``` js
108
- let increasing = compare .increasing ;
109
- let decreasing = compare .decreasing ;
110
-
111
- increasing ( 1 , 1 ) === 0 ; // true
112
- increasing ( 1 , 2 ) < 0 ; // true
113
- increasing ( 2 , 1 ) > 0 ; // true
114
- decreasing ( 1 , 1 ) === 0 ; // true
115
- decreasing ( 1 , 2 ) > 0 ; // true
116
- decreasing ( 2 , 1 ) < 0 ; // true
117
-
118
- let lexicographical = compare .lexicographical ( increasing ) ;
119
-
120
- lexicographical ( [ 1 , 1 ] , [ 1 , 1 ] ) === 0 ; // true
121
- lexicographical ( [ 1 , 1 ] , [ 1 , 2 ] ) < 0 ; // true
122
- lexicographical ( [ 1 , 2 ] , [ 1 , 1 ] ) > 0 ; // true
123
-
124
- lexicographical ( [ 1 , 1 ] , [ 1 , 1 , 1 ] ) < 0 ; // true
125
- lexicographical ( [ 1 , 1 , 1 ] , [ 1 , 1 ] ) > 0 ; // true
126
- lexicographical ( [ 2 , 1 ] , [ 1 , 1 , 1 ] ) > 0 ; // true
127
- lexicographical ( [ 1 , 1 , 1 ] , [ 2 , 1 ] ) < 0 ; // true
128
-
129
- let reverselexicographical = compare .reverse ( lexicographical ) ;
130
-
131
- reverselexicographical ( [ 1 , 1 ] , [ 1 , 1 ] ) === 0 ; // true
132
- reverselexicographical ( [ 1 , 1 ] , [ 1 , 2 ] ) > 0 ; // true
133
- reverselexicographical ( [ 1 , 2 ] , [ 1 , 1 ] ) < 0 ; // true
134
-
135
- reverselexicographical ( [ 1 , 1 ] , [ 1 , 1 , 1 ] ) > 0 ; // true
136
- reverselexicographical ( [ 1 , 1 , 1 ] , [ 1 , 1 ] ) < 0 ; // true
137
- reverselexicographical ( [ 2 , 1 ] , [ 1 , 1 , 1 ] ) < 0 ; // true
138
- reverselexicographical ( [ 1 , 1 , 1 ] , [ 2 , 1 ] ) > 0 ; // true
139
-
140
- // ... and many more variants.
141
-
142
- /** compare backwards, if identical compare length */
143
- let increasing = compare .colexicographical ( compare .increasing ) ;
144
- /** compare length first, if identical compare forwards */
145
- let increasing = compare .quasilexicographical ( compare .increasing ) ;
146
- /** compare length first, if identical compare backwards */
147
- let increasing = compare .quasicolexicographical ( compare .increasing ) ;
148
- /** compare components in range [0, 3[, forwards */
149
- let increasing = compare .fixedlexicographical ( compare .increasing , 3 ) ;
150
- /** compare components in range [0, 3[, backwards */
151
- let increasing = compare .fixedcolexicographical ( compare .increasing , 3 ) ;
152
- /** compare components in range [1, 4[, forwards */
153
- let increasing = compare .rangedlexicographical ( compare .increasing , 1 , 4 ) ;
154
- /** compare components in range [1, 4[, backwards */
155
- let increasing = compare .rangedcolexicographical ( compare .increasing , 1 , 4 ) ;
156
-
157
- // Also includes comparison function creation tools. Hereunder, all versions are equivalent.
158
- let operator = require ( " @aureooms/js-operator" ) ;
159
- let increasing = compare .fn ( compare .increasing , operator .len ) ;
160
- let increasing = compare .attr ( compare .increasing , " length" ) ;
161
- let increasing = compare .len ( compare .increasing ) ;
162
-
163
- // Plus an additional useful tool.
164
- compare .sign ( - 2378 ) === - 1 ; // true
165
- compare .sign ( 0 ) === 0 ; // true
166
- compare .sign ( 2378 ) === 1 ; // true
167
- ```
168
-
169
27
## References
170
28
171
29
- https://en.wikipedia.org/wiki/Lexicographical_order
0 commit comments