Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
339 B
2
Indexable
const bubblesort = (arr) => {
  const size = arr.length

  for( var i = 0 ; i < size-1; i ++ ){
    for( var j = 0; j < size - i - 1; j++)
    {
      if ( arr[j] > arr[j + 1]){
        var temp = arr[j] ;
        arr[j] = arr[j+1];
        arr[j+1] = temp;
      }
    }
  }

}
const a = [10,6,7,5,8,4,2,3,1]

bubblesort(a)
console.log(a)
Leave a Comment