Sorts an unsorted numeric array into ascending order using a bubble sort.
var data = [ 4, 9, 2, 6, 3, 1, 7, 10, 5, 8 ] ;
bubble( data);
// modifies data into ascending orderTo run the example code from the top-level application directory,
$ node ./examples/index.jsFor an array containing n elements, after performing the last swap, the algorithm performs n further comparisons before concluding that array is sorted.
Over 100,000 runs,
| Array size | Mean passes |
|---|---|
| 5 | 3.19 |
| 10 | 6.83 |
| 50 | 41.6 |
| 100 | 87.7 |
| 500 | 470.4 |
In directory /testing:
- Edit array size and desired number of runs in index_examples_testrun.js.
- To run,
node index_examples_testrun.jsFor an unsorted array of size n, the time to sort the array using bubble sort is:
| n | Time (ms) |
|---|---|
| 5 | 10.7 |
| 50 | 11.4 |
| 500 | 14.6 |
| 5000 | 167 |
| 50000 | 15778 |
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.