Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
bubblesort
Advanced tools
Readme
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.
$ npm install --save bubblesort
var bubblesort = require('bubblesort');
// Ascending order
bubblesort([3,1,4,1,5,9,2,6,5,4]);
// => [1,1,2,3,4,4,5,5,6,9]
bubblesort([9,2,8,6,1,3]);
// => [1,2,3,6,8,9]
bubblesort([5,2,4,6,1,3]);
// => [1,2,3,4,5,6]
// Descending order
function comparator(a, b) { return b - a; }
bubblesort([5,2,2,6,1,3], comparator);
// => [6,5,3,2,2,1]
bubblesort([0,0,0,0,0,-1], comparator);
// => [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}
];
function comparePeople(a, b) { return a.age - b.age };
bubblesort(people, comparePeople);
/*
=> [
{"name": 'Passy', "age": 25, "place": 1},
{"name": 'Sindre', "age": 30, "place": 2},
{"name": 'Matt', "age": 35, "place": 3},
{"name": 'Stephen', "age": 40, "place": 4}
]
*/
MIT © Addy Osmani
FAQs
Bubble Sort
The npm package bubblesort receives a total of 49 weekly downloads. As such, bubblesort popularity was classified as not popular.
We found that bubblesort demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.