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