sorting-algorithms-lib
Version:
sorting-algorithms-lib is a lightweight JavaScript library that provides efficient implementations of various sorting algorithms. Whether you're learning algorithms, benchmarking performance, or building a project that requires sorting, this library has y
23 lines (17 loc) • 499 B
text/typescript
const { swap } = require('../utils/swap');
export function selectionSort(inputArr: Array<number> | Array<string>): Array<any> {
let minValue: number | string;
let minIndex: number;
for (let i=0; i < inputArr.length-1; ++i) {
minValue = inputArr[i];
minIndex = i;
for (let j=i+1; j <= inputArr.length-1; ++j) {
if (inputArr[j] < minValue) {
minValue = inputArr[j];
minIndex = j;
}
}
swap(inputArr, i, minIndex, );
}
return inputArr;
}