Skip to content

Instantly share code, notes, and snippets.

@jeffwesson
Last active April 1, 2016 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffwesson/d4f911cd2b33bd52a020e8036492dd64 to your computer and use it in GitHub Desktop.
Save jeffwesson/d4f911cd2b33bd52a020e8036492dd64 to your computer and use it in GitHub Desktop.
BubbleSort Algorithm
const bubbleSort = function (arr) {
let store = null;
let maxProfit = 0;
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr.length - 1; j++) {
if (arr[j] > arr[j + 1]) {
store = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = store;
}
}
}
return arr;
};
const prices = [-53, -41, -4, -2, -12, -15, -6];
console.log(bubbleSort(prices));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment