Produces a sorted (ascending) array from an unsorted numeric array using a quicksort.
// Direct to lib directory
var qsort = require( './../lib' );
// Create some data
var data = new Array( 5 );
for ( var i = 0; i < data.length; i++ ) {
data[ i ] = Math.round( Math.random()*100 );
}
// Print unsorted array for comparison
console.log("Pre-sort:")
for ( var i = 0; i < data.length; i++ ) {
console.log( data[i] );
}
// Apply qsort to unsorted array, set output equal to new variable
var data_sorted = qsort( data );
// Print new, sorted array
console.log("Post-sort:")
for ( var i = 0; i < data_sorted.length; i++ ) {
console.log( data_sorted[i] );
}Not in place - original unsorted array is unmodified.
For an unsorted array of size n, the time to sort the array using bubble sort is:
| n | Time (ms) |
|---|---|
| 5 | |
| 50 | |
| 500 | |
| 5000 | |
| 50000 |
Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:
$ make testAll new feature development should have corresponding unit tests to validate correct functionality.
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-covIstanbul creates a ./reports/coverage directory. To access an HTML version of the report,
$ make view-covCopyright © 2014. Rebekah Smith.