We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 92a85af commit 67269fdCopy full SHA for 67269fd
algorithms/sorting/bubble-sort/bubble-sort.js
@@ -0,0 +1,23 @@
1
+/*
2
+ * Bubble sort implementation in JavaScript
3
+ * Copyright (c) 2009 Nicholas C. Zakas
4
+ * MIT Licensed - see LICENSE for details on license.
5
+ */
6
+
7
+/**
8
+ * A bubble sort implementation in JavaScript. The array
9
+ * is sorted in-place.
10
+ * @param {Array} items An array of items to sort.
11
12
13
+function sort(items){
14
+ for (var i=items.length-1; i >= 0; i--){
15
+ for (var j=i; j >= 0; j--){
16
+ if (items[j] < items[j-1]){
17
+ var temp = items[j];
18
+ items[j] = items[j-1];
19
+ items[j-1] = temp;
20
+ }
21
22
23
+}
0 commit comments