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.

23 lines (20 loc) 448 B
/** * @public * Strips null and undefined items from arrays (non mutative). * * @remarks * See {@link arrayCompact}. */ export function arrayCompact<TItem>(items: ArrayLike<TItem | null | undefined>): TItem[] { const result: TItem[] = []; for (let i = 0, iEnd = items.length; i < iEnd; ++i) { const item = items[i]; if (item != null) { result.push(item); } } return result; }