Sorts an unsorted numeric array into ascending order using a selection sort.
// Direct to lib directory
var sel = 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 );
}
//var data = [ 5, 7, 3 ]
// Print data for comparison
console.log("Pre-sort:")
for ( var i = 0; i < data.length; i++ ) {
console.log( data[i] );
}
// Sort data
sel( data );
// Print sorted array
console.log("Post-sort:")
for ( var i = 0; i < data.length; i++ ) {
console.log( data[i] );
}For an unsorted array of size n, the time to sort the array using bubble sort is:
| n | Time (ms) |
|---|---|
| 5 | 10.0 |
| 50 | 10.1 |
| 500 | 13.0 |
| 5000 | 57.3 |
| 50000 | 4541 |
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.