Skip to content

data-structures-and-algorithms/selection

Repository files navigation

Selection code bricks for JavaScript. Parent is aureooms/js-sort.

let quickselect = selection.singletco( partition.hoare ) ;

NPM license NPM version Bower version Build Status Coverage Status Dependencies Status devDependencies Status Code Climate NPM downloads per month GitHub issues Inline docs

Can be managed through jspm, duo, component, bower, ender, jam, spm, and npm.

Install

jspm

jspm install github:aureooms/js-selection
# or
jspm install npm:aureooms-js-selection

duo

No install step needed for duo!

component

component install aureooms/js-selection

bower

bower install aureooms-js-selection

ender

ender add aureooms-js-selection

jam

jam install aureooms-js-selection

spm

spm install aureooms-js-selection --save

npm

npm install aureooms-js-selection --save

Require

jspm

let selection = require( "github:aureooms/js-selection" ) ;
// or
import selection from 'aureooms-js-selection' ;

duo

let selection = require( "aureooms/js-selection" ) ;

component, ender, spm, npm

let selection = require( "aureooms-js-selection" ) ;

bower

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.

jam

require( [ "aureooms-js-selection" ] , function ( selection ) { ... } ) ;

Use

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 ) ;

Packages

No packages published

Contributors 2

  •  
  •