JSFiddle - React, Tailwind, and code Playground

by Sudheer Nunna

JavaScript

function bubbleSort(array) {
  var next2last = array.length - 1;
  array.some(function() {
    var isNotSwapped = true;
    for (var index = 0; index < next2last; index += 1) {
      var nextIndex = index + 1;
      if (array[index] > array[nextIndex]) {
        var holder = array[nextIndex];
        array[nextIndex] = array[index];
        array[index] = holder;
        isNotSwapped = false;
      }
    }
    return isNotSwapped;
  });
}

var numbers = [12, 10, 15, 11, 14, 13, 16];
bubbleSort(numbers);
console.log(numbers);