showing results for - "boble sorting javascript"
Julian
14 Sep 2018
1function bubbleSort(array) {
2	for (let i = 0; i < array.length; i++) {
3		for (let j = 0; j < array.length; j++) {
4			let item = array[j];
5
6			var nextItem = array[j + 1];
7			if (item > nextItem) {
8				array[j] = nextItem;
9				array[j + 1] = item;
10			}
11		}
12	}
13	return array;
14}
15
16console.log(bubbleSort([9, 5, 7, 1, 0, 2, 4, 10, 1, 6, 3, 5, 8]));
17console.log(bubbleSort([900, 5, 70, 0.1, 0, 02, 4, 100, 1, 6, 35, 56, 8]));
Chloé
07 Jan 2018
1function bubblesort(array) {
2    len = array.length;
3
4    for (let i = 0; i < len; i++) {
5        for (let j = 0; j < len - i; j++) {
6            let a = array[j];
7            if (a != array[-1]) {
8                var b = array[j + 1];
9                if (a > b) {
10                    array[j] = b;
11                    array[j + 1] = a;
12                }
13            }
14        }
15    }
16}
17
18let array = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1];
19bubblesort(array);
20console.log(array)
Fabiana
05 Jun 2020
1// like using Array.reverse();
2function bubbleReverse(arr) {
3    for (let i = arr.length - 1; i > 0; i--) {
4        for (let j = arr.length - 1; j > 0; j--) {
5            if (arr[j] > arr[j - 1]) {
6                let temp = arr[j];
7                arr[j] = arr[j - 1];
8                arr[j - 1] = temp;
9            }
10        }
11    }
12    return arr;
13}
14
15// like using Array.sort();
16function bubbleSort(arr) {
17    for (let i = 0; i < arr.length - 1; i++) {
18        for (let j = 0; j < arr.length - 1; j++) {
19            if (arr[j] > arr[j + 1]) {
20                let temp = arr[j];
21                arr[j] = arr[j + 1];
22                arr[j + 1] = temp;
23            }
24        }
25    }
26    return arr;
27}
queries leading to this page
bubble event in javascriptjavascript bubblesortjs bubblesortbubble sort question in javasccriptbubble sort once jsbuble sort funciton javascriptbubble sort in javasciptjavascript algorithms e2 80 94 bubble sort sidepointjavascript bubble sort last valuebubble sort javascript descriptionbubble sort htmlbubble sort method javascriptbubblesort array jsperform swapping and sorting in javascriptjavascript bubleshort examplebubble sort javascript entire codebubble jsjs buble sortwhat is bubble in javascriptbubble sort in jsbubble sotrng jshow to write bubble sort function jshow to buble sort an array of numbers in javascriptpseudocode of bubble sort javascriptbubble char algorithm javascriptjavascript sort bubblebubble sort javasrciptbubble sort arraybubble sort array javascriptbubble sort javascriptbubble short in javascriptbubble javascriptjavascript bubble sort algorithmbubble grouping algorithm javascriptsort array bubblebubble sort algorithm in javascriptarray bubble sortboble sorting javascriptwrite a program in javascript to implement a bubble sort algorithmbubble sort jsbubble sort algorithm javascriptbubble sort javascript codehow to use bubble sort in javascriptbubble sort javascript algorithmbubble sort techniques jsjavascript bubble sort numbersbubble sort function javascriptbubble sort jsbubble sort javascript w3schoolsbuble sort jsbubble srt jsbubblesort javascriptbubble sort javascript ascendingjs bubble sortbubble sort in javascriptbubble sort in node jsbubble sorting javascriptbubble sort loop jsjavascript bubble sort functionjs bubble sort algorithmeasy bobble sort javascriptbubble in array bobule sort in jsbubble sort javacriptjavascript bubblejavascript bubble sortbubble sort code in javascriptjavascript bubble soerbubble sort mdncode to write bubblesort in javascripthow to implement bubble sort javascriptbubble sort algorithm jsbubble jsbubble sorting code jsbubble algorithm javascriptbubble sort node jsbubble sort program in javascriptvanilla javascript bubble sortis js sort a bubble sortbubble sort why is it important jsbubble sort array with swap javascriptpseudocode bubble sort javascriptbubble sort technique javascriptbuble sort in javascriptbubble sort algorithm js tutorialbubble sort code javascriptbuuble sort javascriptbubblesort in javascriptjavascript bubble sort an arraybubble sort array jsbubblesort jsbubble sort an array javascriptboble sorting javascript