Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 18 lines (12 sloc) 618 Bytes
import { slice } from './slice';
export function splice<T>(array: T[], insertAtIndex: number, removeNumberOfElements: number, ...values: T[]) {
const firstPart = slice(array, 0, insertAtIndex);
const secondPart = slice(array, insertAtIndex + removeNumberOfElements);
const removedElements = slice(array, insertAtIndex, insertAtIndex + removeNumberOfElements);
const joinedParts = firstPart.concat(values, secondPart);
const { length: joinedPartsLength } = joinedParts;
for (let index = 0; index < joinedPartsLength; index += 1) {
array[index] = joinedParts[index];
}
return removedElements;
}
You can’t perform that action at this time.