mars-v2-frontend/src/utils/array.ts

15 lines
572 B
TypeScript
Raw Normal View History

2023-06-15 12:34:12 +00:00
export const byDenom = (denom: string) => (entity: any) => entity.denom === denom
export const bySymbol = (symbol: string) => (entity: any) => entity.symbol === symbol
export const byTokenDenom = (denom: string) => (entity: any) => entity.token.denom === denom
export function partition<T>(arr: Array<T>, predicate: (val: T) => boolean): [Array<T>, Array<T>] {
const partitioned: [Array<T>, Array<T>] = [[], []]
arr.forEach((val: T) => {
const partitionIndex: 0 | 1 = predicate(val) ? 0 : 1
partitioned[partitionIndex].push(val)
})
return partitioned
}