Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

sorting array without sort method in javascript

let arr = [4, 32, 2, 5, 8];

for (let i = 0; i < arr.length; i++) {
  for (let j = i + 1; j < arr.length; j++) {
    if (arr[i] > arr[j]) {
      temp = arr[i];
      arr[i] = arr[j];
      arr[j] = temp;
    }
  }
}
console.log("Sorted array=>", arr);
Comment

how to sort array without using sort method in javascript

function bubbleSort(array) {
  var done = false;
  while (!done) {
    done = true;
    for (var i = 1; i < array.length; i += 1) {
      if (array[i - 1] > array[i]) {
        done = false;
        var tmp = array[i - 1];
        array[i - 1] = array[i];
        array[i] = tmp;
      }
    }
  }

  return array;
}

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

PREVIOUS NEXT
Code Example
Javascript :: get 3 random items from array javascript 
Javascript :: how to check vowels in a string in javascript 
Javascript :: express.js routing 
Javascript :: firebase hosting rewrite function You need to enable JavaScript to run this app. 
Javascript :: javascript detect if active element is writable 
Javascript :: d3 js date scatter plot 
Javascript :: canvas squashed video javascript 
Javascript :: js if on cellular network 
Javascript :: rest object javascript 
Javascript :: express check request type 
Javascript :: javascript complex literal 2 
Javascript :: html video api set speed 
Javascript :: javascript flow function 
Javascript :: counter plus minus for quantity 
Javascript :: js delete without changing index 
Javascript :: jsdoc run for all files in folder 
Javascript :: create index with multiple fields mongo 
Javascript :: jsf localdate converter 
Javascript :: how do i set CORS policy for nodejs sever 
Javascript :: angularjs Both ng-model and ng-change on input alter the $scope state - which one takes priority 
Javascript :: Prevent the wiping of an Array after routing Angular.js 
Javascript :: AngularJS slick carousel filter by attribute 
Javascript :: sfc setup vue 3 mounted method - lifecycle methods in sfc 
Javascript :: the given sign-in provider is disabled for this firebase project 
Javascript :: How to access a preexisting collection with Mongoose 
Javascript :: Triggering An Event Programmatically With JavaScript 
Javascript :: assign single value to multiple variables in React js Or javacript 
Javascript :: phaser matrix rotate 
Javascript :: yoptascript 
Javascript :: react sate and props 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =