UNPKG

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

21 lines (20 loc) 599 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.selectionSort = selectionSort; const { swap } = require('../utils/swap'); function selectionSort(inputArr) { let minValue; let minIndex; 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; }