Bubble Sort
Bubble Sort implementation wth O(n^2) complexity based on JavaScript Algorithms.
Bubble sort is a simple sorting algorithm that repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the wrong order.
Install
$ npm install --save bubblesort
Usage
var bubblesort = ; // Ascending order ;// => [1,1,2,3,4,4,5,5,6,9] ;// => [1,2,3,6,8,9] ;// => [1,2,3,4,5,6] // Descending order { return b - a; } ;// => [6,5,3,2,2,1] ;// => [0,0,0,0,0,-1] // Ascending sort arrays of objects var people = name: 'Sindre' age: 30 place: 2 name: 'Passy' age: 25 place: 1 name: 'Stephen' age: 40 place: 4 name: 'Matt' age: 35 place: 3; { return aage - bage }; ;/*=> [ {"name": 'Passy', "age": 25, "place": 1}, {"name": 'Sindre', "age": 30, "place": 2}, {"name": 'Matt', "age": 35, "place": 3}, {"name": 'Stephen', "age": 40, "place": 4}]*/
License
MIT © Addy Osmani