Skip to content

Commit

Permalink
refactor: optimize selection sort
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhermawan committed Sep 12, 2023
1 parent af41896 commit c1de73b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ export function selectionSort<T>(arr: T[], compareFn: CompareFn<T>): T[] {
}

if (minIndex !== i) {
const temp = sortedArray[i];
sortedArray[i] = sortedArray[minIndex];
sortedArray[minIndex] = temp;
[sortedArray[i], sortedArray[minIndex]] = [
sortedArray[minIndex],
sortedArray[i],
];
}
}

Expand Down

0 comments on commit c1de73b

Please sign in to comment.