UNPKG

@kuzanatoliorg/algorithms

Version:

The utils package for react testing library

23 lines (22 loc) 675 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.selectionSort = void 0; const utils_1 = require("../utils"); const selectionSort = (arr, comparator = utils_1.defaultComparator, order = true) => { let i, j, temp, item; for (i = 0; i < arr.length; i++) { temp = i; for (j = i + 1; j < arr.length; j++) { if (order ? comparator(arr[j], arr[temp]) : comparator(arr[temp], arr[j])) { temp = j; } } item = arr[i]; arr[i] = arr[temp]; arr[temp] = item; } return arr; }; exports.selectionSort = selectionSort;