GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — stop bubble sort revisiting already sorted elements · BrandonWeb/javascript-algorithms@d0ed0af

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src/algorithms/sorting/bubble-sort
    • BubbleSort.js
    • __test__
      • BubbleSort.test.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/algorithms/sorting/bubble-sort/BubbleSort.js‎

Copy file name to clipboardExpand all lines: src/algorithms/sorting/bubble-sort/BubbleSort.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ export default class BubbleSort extends Sort {
77
// Clone original array to prevent its modification.
88
const array = originalArray.slice(0);
99

10-
for (let i = 0; i < array.length; i += 1) {
10+
for (let i = 1; i < array.length; i += 1) {
1111
swapped = false;
1212

1313
// Call visiting callback.
1414
this.callbacks.visitingCallback(array[i]);
1515

16-
for (let j = 0; j < array.length - 1; j += 1) {
16+
for (let j = 0; j < array.length - i; j += 1) {
1717
// Call visiting callback.
1818
this.callbacks.visitingCallback(array[j]);
1919

Collapse file

‎src/algorithms/sorting/bubble-sort/__test__/BubbleSort.test.js‎

Copy file name to clipboardExpand all lines: src/algorithms/sorting/bubble-sort/__test__/BubbleSort.test.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {
99

1010
// Complexity constants.
1111
const SORTED_ARRAY_VISITING_COUNT = 20;
12-
const NOT_SORTED_ARRAY_VISITING_COUNT = 280;
13-
const REVERSE_SORTED_ARRAY_VISITING_COUNT = 400;
12+
const NOT_SORTED_ARRAY_VISITING_COUNT = 189;
13+
const REVERSE_SORTED_ARRAY_VISITING_COUNT = 209;
1414
const EQUAL_ARRAY_VISITING_COUNT = 20;
1515

1616
describe('BubbleSort', () => {

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.