Last active
April 1, 2016 06:39
-
-
Save jeffwesson/d4f911cd2b33bd52a020e8036492dd64 to your computer and use it in GitHub Desktop.
BubbleSort Algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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