JSFiddle - React, Tailwind, and code Playground

by Artem

JavaScript

'use strict';

const bubleSort = arr => {
  let endIndex = arr.length - 1;
  let sorted = false;

  while (!sorted) {
	  sorted = true;

    for (let i = 0; i < endIndex; i++) {
      const cur = arr[i];
      const next = arr[i + 1];

      if (cur > next) {
        arr[i] = next;
        arr[i + 1] = cur;
        sorted = false;
      }
    }
		
		endIndex--;
  }
};


console.log(bubbleSort([1, 4, 10]));