Path: blob/main/extensions/markdown-language-features/src/util/arrays.ts
3292 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/4/**5* @returns New array with all falsy values removed. The original array IS NOT modified.6*/7export function coalesce<T>(array: ReadonlyArray<T | undefined | null>): T[] {8return <T[]>array.filter(e => !!e);9}1011export function equals<T>(one: ReadonlyArray<T>, other: ReadonlyArray<T>, itemEquals: (a: T, b: T) => boolean = (a, b) => a === b): boolean {12if (one.length !== other.length) {13return false;14}1516for (let i = 0, len = one.length; i < len; i++) {17if (!itemEquals(one[i], other[i])) {18return false;19}20}2122return true;23}242526