Skip to content

Instantly share code, notes, and snippets.

@rajatk16
Created December 18, 2018 00:27
Show Gist options
  • Select an option

  • Save rajatk16/4bb6e8e1f70097ca4aafd773e1c21da9 to your computer and use it in GitHub Desktop.

Select an option

Save rajatk16/4bb6e8e1f70097ca4aafd773e1c21da9 to your computer and use it in GitHub Desktop.
bubbleSort = (array) => {
let swapped = false
do {
swapped = false
array.forEach((current, i) => {
console.log(array.join(' '))
if (current > array[i + 1]) {
const temp = current
console.log(array.join(' '))
array[i] = array[i + 1]
array[i + 1] = temp
swapped = true
}
})
} while(swapped)
console.log(array.join(' '))
return array
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment