Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
060c808
commit 730058a
Showing
6 changed files
with
103 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,65 @@ | ||
# Examples | ||
|
||
> More examples in [the test files](https://github.com/{repository}/tree/master/test/src). | ||
> More examples in [the test files](https://github.com/aureooms/js-compare/tree/master/test/src). | ||
```js | ||
let increasing = compare.increasing ; | ||
let decreasing = compare.decreasing ; | ||
|
||
increasing( 1 , 1 ) === 0 ; // true | ||
increasing( 1 , 2 ) < 0 ; // true | ||
increasing( 2 , 1 ) > 0 ; // true | ||
decreasing( 1 , 1 ) === 0 ; // true | ||
decreasing( 1 , 2 ) > 0 ; // true | ||
decreasing( 2 , 1 ) < 0 ; // true | ||
|
||
let lexicographical = compare.lexicographical( increasing ) ; | ||
|
||
lexicographical( [ 1 , 1 ] , [ 1 , 1 ] ) === 0 ; // true | ||
lexicographical( [ 1 , 1 ] , [ 1 , 2 ] ) < 0 ; // true | ||
lexicographical( [ 1 , 2 ] , [ 1 , 1 ] ) > 0 ; // true | ||
|
||
lexicographical( [ 1 , 1 ] , [ 1 , 1 , 1 ] ) < 0 ; // true | ||
lexicographical( [ 1 , 1 , 1 ] , [ 1 , 1 ] ) > 0 ; // true | ||
lexicographical( [ 2 , 1 ] , [ 1 , 1 , 1 ] ) > 0 ; // true | ||
lexicographical( [ 1 , 1 , 1 ] , [ 2 , 1 ] ) < 0 ; // true | ||
|
||
let reverselexicographical = compare.reverse( lexicographical ) ; | ||
|
||
reverselexicographical( [ 1 , 1 ] , [ 1 , 1 ] ) === 0 ; // true | ||
reverselexicographical( [ 1 , 1 ] , [ 1 , 2 ] ) > 0 ; // true | ||
reverselexicographical( [ 1 , 2 ] , [ 1 , 1 ] ) < 0 ; // true | ||
|
||
reverselexicographical( [ 1 , 1 ] , [ 1 , 1 , 1 ] ) > 0 ; // true | ||
reverselexicographical( [ 1 , 1 , 1 ] , [ 1 , 1 ] ) < 0 ; // true | ||
reverselexicographical( [ 2 , 1 ] , [ 1 , 1 , 1 ] ) < 0 ; // true | ||
reverselexicographical( [ 1 , 1 , 1 ] , [ 2 , 1 ] ) > 0 ; // true | ||
|
||
// ... and many more variants. | ||
|
||
/** compare backwards, if identical compare length */ | ||
let increasing = compare.colexicographical( compare.increasing ) ; | ||
/** compare length first, if identical compare forwards */ | ||
let increasing = compare.quasilexicographical( compare.increasing ) ; | ||
/** compare length first, if identical compare backwards */ | ||
let increasing = compare.quasicolexicographical( compare.increasing ) ; | ||
/** compare components in range [0, 3[, forwards */ | ||
let increasing = compare.fixedlexicographical( compare.increasing , 3 ) ; | ||
/** compare components in range [0, 3[, backwards */ | ||
let increasing = compare.fixedcolexicographical( compare.increasing , 3 ) ; | ||
/** compare components in range [1, 4[, forwards */ | ||
let increasing = compare.rangedlexicographical( compare.increasing , 1 , 4 ) ; | ||
/** compare components in range [1, 4[, backwards */ | ||
let increasing = compare.rangedcolexicographical( compare.increasing , 1 , 4 ) ; | ||
|
||
// Also includes comparison function creation tools. Hereunder, all versions are equivalent. | ||
let operator = require( "@aureooms/js-operator" ) ; | ||
let increasing = compare.fn( compare.increasing , operator.len ) ; | ||
let increasing = compare.attr( compare.increasing , "length" ) ; | ||
let increasing = compare.len( compare.increasing ) ; | ||
|
||
// Plus an additional useful tool. | ||
compare.sign( -2378 ) === -1 ; // true | ||
compare.sign( 0 ) === 0 ; // true | ||
compare.sign( 2378 ) === 1 ; // true | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
var domReady = function(callback) {{ | ||
var domReady = function(callback) { | ||
var state = document.readyState ; | ||
if ( state === 'interactive' || state === 'complete' ) {{ | ||
if ( state === 'interactive' || state === 'complete' ) { | ||
callback() ; | ||
}} | ||
else {{ | ||
} | ||
else { | ||
document.addEventListener('DOMContentLoaded', callback); | ||
}} | ||
}} ; | ||
} | ||
} ; | ||
|
||
|
||
domReady(function(){{ | ||
domReady(function(){ | ||
|
||
var projectname = document.createElement('a'); | ||
projectname.classList.add('project-name'); | ||
projectname.text = '{repository}'; | ||
projectname.text = 'aureooms/js-compare'; | ||
projectname.href = './index.html' ; | ||
|
||
var header = document.getElementsByTagName('header')[0] ; | ||
header.insertBefore(projectname,header.firstChild); | ||
|
||
var testlink = document.querySelector('header > a[data-ice="testLink"]') ; | ||
testlink.href = 'https://coveralls.io/github/{repository}' ; | ||
testlink.href = 'https://coveralls.io/github/aureooms/js-compare' ; | ||
testlink.target = '_BLANK' ; | ||
|
||
var searchBox = document.querySelector('.search-box'); | ||
var input = document.querySelector('.search-input'); | ||
|
||
// active search box when focus on searchBox. | ||
input.addEventListener('focus', function(){{ | ||
input.addEventListener('focus', function(){ | ||
searchBox.classList.add('active'); | ||
}}); | ||
}); | ||
|
||
}}); | ||
}); |