Skip to content

Commit

Permalink
utils: remove arrIndexOf polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
mschristensen committed Mar 5, 2024
1 parent f994792 commit 98798a5
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions src/common/lib/util/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,21 +174,6 @@ export function arrSubtract<T>(arr1: Array<T>, arr2: Array<T>): Array<T> {
return result;
}

export const arrIndexOf = (Array.prototype.indexOf as unknown)
? function (arr: Array<unknown>, elem: unknown, fromIndex?: number) {
return arr.indexOf(elem, fromIndex);
}
: function (arr: Array<unknown>, elem: unknown, fromIndex?: number) {
fromIndex = fromIndex || 0;
const len = arr.length;
for (; fromIndex < len; fromIndex++) {
if (arr[fromIndex] === elem) {
return fromIndex;
}
}
return -1;
};

export function arrIndexOfBy<T>(
arr: Array<T>,
iteratee: (value: T) => unknown,
Expand All @@ -205,15 +190,15 @@ export function arrIndexOfBy<T>(
}

export function arrUnique<T>(arr: Array<T>): Array<T> {
return arr.filter((value, index) => arrIndexOf(arr, value) === index);
return arr.filter((value, index) => arr.indexOf(value) === index);
}

export function arrUniqueBy<T>(arr: Array<T>, iteratee: (value: T) => unknown): Array<T> {
return arr.filter((value, index) => arrIndexOfBy(arr, iteratee, iteratee(value)) === index);
}

export function arrIn(arr: Array<unknown>, val: unknown): boolean {
return arrIndexOf(arr, val) !== -1;
return arr.indexOf(val) !== -1;
}

export function arrDeleteValue<T>(arr: Array<T>, val: T): boolean {
Expand Down

0 comments on commit 98798a5

Please sign in to comment.