Selection code bricks for JavaScript. Parent is aureooms/js-sort.
let quickselect = selection.singletco( partition.hoare ) ;
Can be managed through jspm, duo, component, bower, ender, jam, spm, and npm.
jspm install github:aureooms/js-selection
# or
jspm install npm:aureooms-js-selection
No install step needed for duo!
component install aureooms/js-selection
bower install aureooms-js-selection
ender add aureooms-js-selection
jam install aureooms-js-selection
spm install aureooms-js-selection --save
npm install aureooms-js-selection --save
let selection = require( "github:aureooms/js-selection" ) ;
// or
import selection from 'aureooms-js-selection' ;
let selection = require( "aureooms/js-selection" ) ;
let selection = require( "aureooms-js-selection" ) ;
The script tag exposes the global variable selection
.
<script src="bower_components/aureooms-js-selection/js/dist/selection.min.js"></script>
Alternatively, you can use any tool mentioned here.
require( [ "aureooms-js-selection" ] , function ( selection ) { ... } ) ;
let partition = require( "aureooms-js-partition" ) ;
let compare = require( "aureooms-js-compare" ) ;
/** recursive single pivot quickselect using Hoare's partitioning algorithm*/
let select = selection.single( partition.hoare ) ;
let a = [ 1 , 6 , 5 , 3 , 2 , 4 ] ;
select( compare.increasing , a , 0 , a.length , 3 ) ;
a ; // [ . , . , . , 4 , . , . ]
select( compare.decreasing , a , 0 , a.length , 2 ) ;
a ; // [ . , 5 , . , . , . , . ]
// but also
/** recursive single pivot quickselect using Lomuto's partitioning algorithm */
let select = selection.single( partition.lomuto ) ;
/** with explicit tail call optimization */
let select = selection.singletco( partition.hoare ) ;
let select = selection.singletco( partition.lomuto ) ;