UNPKG

rc-js-util

Version:

A collection of TS and C++ utilities to help writing performant and correct applications, achieved through strict typing and (removable) invariant checking.

24 lines (21 loc) 518 B
/** * @public * Removes either 0 or one item from items, even if itemToRemove appears more than once. * * @returns true if an item was removed. * * @remarks * The lowest indexed item will be removed where there is more than one match. * * See {@link arrayRemoveOne}. */ export function arrayRemoveOne<TItem>(items: TItem[], itemToRemove: TItem): boolean { const index = items.indexOf(itemToRemove); if (index === -1) { return false; } items.splice(index, 1); return true; }