Skip to content

Commit 185f630

Browse files
authored
JavaScript
1 parent 59d7d30 commit 185f630

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Odd-Even Sort/OddEvenSort.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
const OddEvenSort = (arr) => {
2+
for (let i = 0; i < arr.length; ++i)
3+
for (let j = i % 2 == 0 ? 0 : 1; j + 1 < arr.length; j += 2)
4+
if (arr[j] > arr[j + 1]) [arr[j], arr[j + 1]] = [arr[j + 1], arr[j]];
5+
return arr;
6+
};

0 commit comments

Comments
 (0)