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 :: action cable nuxtjs 
Javascript :: django restframework jquery post 
Javascript :: file_get_contents api json 
Javascript :: is javascript case sensitive 
Javascript :: When an aqueous solution of AgNO3 is mixed with an aqueous solution of (NH4)2CrO4, a precipitation reaction occurs. For this reaction, a) Write the molecular equation. 
Javascript :: angular append to FormControl errors 
Javascript :: RS Brawijaya Healthcare rumah sakit type 
Javascript :: jquery to javascript converter online 
Javascript :: input type disappear side scroll react 
Javascript :: tomtom map in vuejs 
Javascript :: react algoliasearch 
Javascript :: dropzone not working when input is clicked 
Javascript :: play store version of react native app 
Javascript :: $(document).ready(function() { $(".more-items").click(function() { $(this).parent().find(".more").slideToggle(); }); }); 
Javascript :: how to make an object stop at the end of your canvas p5js 
Javascript :: renderer.setElementStyle 
Javascript :: download print.js rtl 
Javascript :: local = 1 
Javascript :: break string to array javascript without delimeter 
Javascript :: math.random and clone 
Javascript :: left_field in jsgrid 
Javascript :: check textbox value on ng-change value == in angular 
Javascript :: scenario.getname() cucumber-js 
Javascript :: deny ready jquery 
Javascript :: fnserverparams aodata push custom filter 
Javascript :: creating large element in js 
Javascript :: javascript write to text file stack overflow 
Javascript :: react sagas state 
Javascript :: javascript vérifier si une chaine de carctère commence par une majuscule 
Javascript :: advanced data manipulation javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =