Answers for "how to sort array least to greatest javascript stACK"

0

how to sort array least to greatest javascript stACK

function sortArray(array) {
  var temp = 0;
  for (var i = 0; i < array.length; i++) {
    for (var j = i; j < array.length; j++) {
      if (array[j] < array[i]) {
        temp = array[j];
        array[j] = array[i];
        array[i] = temp;
      }
    }
  }
  return array;
}

console.log(sortArray([3,1,2]));
Posted by: Guest on November-26-2019

Code answers related to "how to sort array least to greatest javascript stACK"

Code answers related to "Javascript"

Browse Popular Code Answers by Language