mirror of
https://github.com/c0de-archive/hacktoberfest-2018.git
synced 2025-07-30 13:30:16 +00:00
Added my name and a piece of code
This commit is contained in:
22
code/sort.js
Normal file
22
code/sort.js
Normal file
@@ -0,0 +1,22 @@
|
||||
function (arr) {
|
||||
function swap(i, j) {
|
||||
let temp = arr[i];
|
||||
arr[i] = arr[j];
|
||||
arr[j] = temp;
|
||||
}
|
||||
let n = arr.length;
|
||||
let sw = true;
|
||||
let x = 0;
|
||||
while (sw) {
|
||||
sw = false;
|
||||
x = x + 1;
|
||||
for (let i = 1;i<=(n-x);i++) {
|
||||
if (arr[i - 1] > arr[i]) {
|
||||
swap(i - 1, i);
|
||||
sw = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return arr
|
||||
}
|
Reference in New Issue
Block a user