@newdash/newdash
Version:
javascript/typescript utility library
51 lines (50 loc) • 1.83 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.pullAt = void 0;
const baseAt_1 = __importDefault(require("./.internal/baseAt"));
const basePullAt_1 = __importDefault(require("./.internal/basePullAt"));
const compareAscending_1 = __importDefault(require("./.internal/compareAscending"));
const isIndex_1 = __importDefault(require("./.internal/isIndex"));
const arrayMap_1 = __importDefault(require("./.internal/arrayMap"));
const flatRest_1 = __importDefault(require("./.internal/flatRest"));
/**
* @ignore
*/
const internalPullAt = (0, flatRest_1.default)((array, indexes) => {
const length = array == null ? 0 : array.length, result = (0, baseAt_1.default)(array, indexes);
(0, basePullAt_1.default)(array, (0, arrayMap_1.default)(indexes, (index) => (0, isIndex_1.default)(index, length) ? +index : index).sort(compareAscending_1.default));
return result;
});
/**
* Removes elements from `array` corresponding to `indexes` and returns an
* array of removed elements.
*
* **Note:** Unlike `at`, this method mutates `array`.
*
* @since 5.11.0
* @category Array
* @param array The array to modify.
* @param indexes The indexes of elements to remove.
* @returns Returns the new array of removed elements.
* @see [[pull]], [[pullAll]], [[pullAllBy]], [[pullAllWith]], [[remove]], [[reject]]
* @example
*
* ```js
* const array = ['a', 'b', 'c', 'd']
* const pulled = pullAt(array, [1, 3])
*
* console.log(array)
* // => ['a', 'c']
*
* console.log(pulled)
* // => ['b', 'd']
* ```
*/
function pullAt(array, ...indexes) {
return internalPullAt(array, ...indexes);
}
exports.pullAt = pullAt;
exports.default = pullAt;