OneCompiler

descending oeder selection sort

107

function selectionsort(a) {
for (let i = 0; i < a.length; i++) {
let max = i;
for (let j = i + 1; j < a.length; j++) {
if (a[max] < a[j]) {
max = j;
}
}

if (i !== max) {
  let temp = a[i];
  a[i] = a[max];
  a[max] = temp;
}

}
return a;
}

const res = selectionsort([34, 25, 24, 5, 8, 2]);
console.log(res);