quicksortjs.sort
is a functional implementation that chooses the first element as the pivot.
quicksortjs.sort2
is an imperative approach that chooses a random pivot.
Usage:
$ quicksortjs 331 2 11 5 17 12 5 55 11 3 222
[ 2, 3, 5, 5, 11, 11, 12, 17, 55, 222, 331 ]
$ quicksortjs -v2 foo bar baz baa
[ 'baa', 'bar', 'baz', 'foo' ]
$ node
> var qs = require('quicksortjs')
undefined
> qs.sort([ 331, 2, 11, 5, 17, 12, 5, 55, 11, 3, 222 ])
[ 2,
3,
5,
5,
11,
11,
12,
17,
55,
222,
331 ]
> qs.sort2([ 'foo', 'bar', 'baz', 'baa' ])
[ 'baa',
'bar',
'baz',
'foo' ]