UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

28 lines (27 loc) 1.15 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const copyArray_1 = __importDefault(require("./copyArray")); const isIndex_1 = __importDefault(require("./isIndex")); const nativeMin_1 = __importDefault(require("./nativeMin")); /** * Reorder `array` according to the specified indexes where the element at * the first index is assigned as the first element, the element at * the second index is assigned as the second element, and so on. * * @private * @param {Array} array The array to reorder. * @param {Array} indexes The arranged array indexes. * @returns {Array} Returns `array`. */ function reorder(array, indexes) { var arrLength = array.length, length = (0, nativeMin_1.default)(indexes.length, arrLength), oldArray = (0, copyArray_1.default)(array); while (length--) { var index = indexes[length]; array[length] = (0, isIndex_1.default)(index, arrLength) ? oldArray[index] : undefined; } return array; } exports.default = reorder;