… prices for metered billing --------- Co-authored-by: Félix Malfait <felix.malfait@gmail.com> Co-authored-by: Félix Malfait <felix@twenty.com>
14 lines
295 B
TypeScript
14 lines
295 B
TypeScript
import { assertIsDefinedOrThrow } from '@/utils';
|
|
|
|
export const findOrThrow = <T>(
|
|
array: T[],
|
|
predicate: (value: T) => boolean,
|
|
error: Error = new Error('Element not found'),
|
|
): T => {
|
|
const result = array.find(predicate);
|
|
|
|
assertIsDefinedOrThrow(result, error)
|
|
|
|
return result;
|
|
};
|