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 :: check angular version 
Javascript :: discordjs 13 TypeError Valid intents must be provided for the Client. 
Javascript :: setup new angular project 
Javascript :: js match alphabet 
Javascript :: href back page javascript 
Javascript :: async iife 
Javascript :: node js remove html tags from string 
Javascript :: javascript check if blank space 
Javascript :: give height to Image in nextjs 
Javascript :: javascript convert float to int 
Javascript :: jquery validation errorplacement 
Javascript :: chartjs how to disable animation 
Javascript :: autocomplete off using jquery 
Javascript :: uppercase string in js 
Javascript :: hash change listener js 
Javascript :: best way to detect mobile device jquery 
Javascript :: js for each character in string 
Javascript :: javascript document load 
Javascript :: empty select option jquery 
Javascript :: jquery each break 
Javascript :: how to get session value using javascript 
Javascript :: js get time in am 
Javascript :: @types react-router-dom 
Javascript :: trim first character in javascript 
Javascript :: node downgrade windows 
Javascript :: self invoked function javascript 
Javascript :: javascript stop setinterval 
Javascript :: display pm or am on date js 
Javascript :: js search json 
Javascript :: how to math 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =