Skip to content

Commit

Permalink
IMplementações
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasZottis committed Oct 2, 2024
1 parent e6bd4ec commit 5a7b936
Showing 1 changed file with 54 additions and 4 deletions.
58 changes: 54 additions & 4 deletions src/extensions/arrayExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,63 @@ export { };

declare global {
interface Array<T> {
contains(predicate: (value: T, index: number, array: T[]) => boolean): boolean;
aggregate(predicate: (previousValue: T, currentValue: T, index: number, array: T[]) => any): T;
all(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): boolean;
any(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): boolean;
append(appendValue: T): T[];
// average(predicate: (previousValue: T, currentValue: T, index: number, array: T[]) => T): T;
cast<TDestination>(): TDestination[];
concat(values: T[]): T[];
contains(searchElement: T): boolean;
count(): number;
}
}

Array.prototype.contains = function <T>(predicate: (value: any, index: number, array: any[]) => any): boolean {
Array.prototype.aggregate = function <T>(predicate: (previousValue: T, currentValue: T, index: number, array: T[]) => T): T {
let list: T[] = this;
let item = list.find(predicate);
return list.reduce(predicate);
}

Array.prototype.all = function <T>(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): boolean {
let list: T[] = this;
return list.every(predicate);
}

Array.prototype.any = function <T>(predicate: (value: T, index: number, array: T[]) => unknown, thisArg?: any): boolean {
let list: T[] = this;
return list.some(predicate);
}

Array.prototype.append = function <T>(appendValue: T): T[] {
let list: T[] = this;
return [...list, appendValue];
}

// Array.prototype.average = function <T>(predicate: (previousValue: T, currentValue: T, index: number, array: T[]) => T): T {
// let list: T[] = this;
// return list.reduce(predicate);
// }

return item !== undefined || item !== null;
Array.prototype.cast = function <T, TDestination extends T>(): TDestination[] {
let list: T[] = this;
return list as TDestination[];
}

Array.prototype.concat = function <T>(values: T[]): T[] {
let list: T[] = this;
return [...list, ...values];
}

Array.prototype.contains = function <T>(searchElement: T): boolean {
let list: T[] = this;
// let item = list.find(predicate);

// return item !== undefined || item !== null;

return list.includes(searchElement);
}

Array.prototype.count = function <T>(): number {
let list: T[] = this;
return list.length;
}

0 comments on commit 5a7b936

Please sign in to comment.