Last active
July 10, 2022 15:54
-
-
Save helabenkhalfallah/7edac1e4b8e3e95341fdbc9431bb877a to your computer and use it in GitHub Desktop.
Vintage Bubble Sort
This file contains hidden or 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 vintageBubbleSort = (data) => { | |
console.log('data input : ', data); | |
for (let i = 0; i < data.length; i++) { | |
console.log('data i : ', data); | |
for (let j = 0; j < data.length; j++) { | |
if (data[j] > data[j + 1]) { | |
let temp = data[j]; | |
data[j] = data[j + 1]; | |
data[j + 1] = temp; | |
} | |
} | |
} | |
return data; | |
}; | |
const tab = [89, 13, 57, 44, 71, 51]; | |
const sortedTab = vintageBubbleSort(tab); | |
console.log('sortedTab : ', sortedTab); | |
/* | |
"data input : ", [89, 13, 57, 44, 71, 51] | |
"data i : ", [89, 13, 57, 44, 71, 51] | |
"data i : ", [13, 57, 44, 71, 51, 89] | |
"data i : ", [13, 44, 57, 51, 71, 89] | |
"data i : ", [13, 44, 51, 57, 71, 89] | |
"data i : ", [13, 44, 51, 57, 71, 89] | |
"data i : ", [13, 44, 51, 57, 71, 89] | |
"sortedTab : ", [13, 44, 51, 57, 71, 89] | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment