Skip to content

Commit

Permalink
feat(uip-setting): create array-utils class
Browse files Browse the repository at this point in the history
create array-utils for easier array's manipulation
  • Loading branch information
Sisha0 committed Apr 4, 2021
1 parent 024148d commit 5f66996
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/utils/array-utils/array-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default class ArrayUtils {
static equals<T>(arr1: T[], arr2: T[]): boolean {
return ArrayUtils.contains(arr1, arr2) && ArrayUtils.contains(arr2, arr1);
}

static contains<T>(array: T[], subArray: T[]): boolean {
return subArray.every(el => array.indexOf(el) !== -1);
}

static select<T>(array: T[], selectItems: T[]): T[] {
return array.filter(el => selectItems.indexOf(el) !== -1);
}

static intersection<T>(...arrays: T[][]): T[] {
return arrays.reduce((inter, array) => ArrayUtils.select(array, inter), arrays[0]);
}
}

0 comments on commit 5f66996

Please sign in to comment.