aboutsummaryrefslogtreecommitdiff
path: root/src/client/northstar/utils/ArrayUtil.ts
diff options
context:
space:
mode:
authorBob Zeleznik <zzzman@gmail.com>2020-04-08 20:56:47 -0400
committerBob Zeleznik <zzzman@gmail.com>2020-04-08 20:56:47 -0400
commit051aefd6455ccda271377913a486e923aef40efd (patch)
treef33e1a52b72bf066e93415a12f47ed74a62f5b4a /src/client/northstar/utils/ArrayUtil.ts
parent9a795d09127d10f23e3992f899265fd227e49af4 (diff)
parentb21db9d40c1619df5455ba8ffe3ef76913cc92de (diff)
Merge branch 'master' into script_documents
Diffstat (limited to 'src/client/northstar/utils/ArrayUtil.ts')
-rw-r--r--src/client/northstar/utils/ArrayUtil.ts90
1 files changed, 0 insertions, 90 deletions
diff --git a/src/client/northstar/utils/ArrayUtil.ts b/src/client/northstar/utils/ArrayUtil.ts
deleted file mode 100644
index 12b8d8e77..000000000
--- a/src/client/northstar/utils/ArrayUtil.ts
+++ /dev/null
@@ -1,90 +0,0 @@
-import { Exception } from "../model/idea/idea";
-
-export class ArrayUtil {
-
- public static Contains(arr1: any[], arr2: any): boolean {
- if (arr1.length === 0) {
- return false;
- }
- let isComplex = typeof arr1[0] === "object";
- for (const ele of arr1) {
- if (isComplex && "Equals" in ele) {
- if (ele.Equals(arr2)) {
- return true;
- }
- }
- else {
- if (ele === arr2) {
- return true;
- }
- }
- }
- return false;
- }
-
-
- public static RemoveMany(arr: any[], elements: Object[]) {
- elements.forEach(e => ArrayUtil.Remove(arr, e));
- }
-
- public static AddMany(arr: any[], others: Object[]) {
- arr.push(...others);
- }
-
- public static Clear(arr: any[]) {
- arr.splice(0, arr.length);
- }
-
-
- public static Remove(arr: any[], other: Object) {
- const index = ArrayUtil.IndexOfWithEqual(arr, other);
- if (index === -1) {
- return;
- }
- arr.splice(index, 1);
- }
-
-
- public static First<T>(arr: T[], predicate: (x: any) => boolean): T {
- let filtered = arr.filter(predicate);
- if (filtered.length > 0) {
- return filtered[0];
- }
- throw new Exception();
- }
-
- public static FirstOrDefault<T>(arr: T[], predicate: (x: any) => boolean): T | undefined {
- let filtered = arr.filter(predicate);
- if (filtered.length > 0) {
- return filtered[0];
- }
- return undefined;
- }
-
- public static Distinct(arr: any[]): any[] {
- let ret = [];
- for (const ele of arr) {
- if (!ArrayUtil.Contains(ret, ele)) {
- ret.push(ele);
- }
- }
- return ret;
- }
-
- public static IndexOfWithEqual(arr: any[], other: any): number {
- for (let i = 0; i < arr.length; i++) {
- let isComplex = typeof arr[0] === "object";
- if (isComplex && "Equals" in arr[i]) {
- if (arr[i].Equals(other)) {
- return i;
- }
- }
- else {
- if (arr[i] === other) {
- return i;
- }
- }
- }
- return -1;
- }
-} \ No newline at end of file