File "find.ts"

Full path: /home/fsibplc/public_html/sommilito-bank2/splide-4.1.3/src/js/utils/arrayLike/find/find.ts
File size: 551 B (551 B bytes)
MIME-type: text/x-java
Charset: utf-8

Download   Open   Edit   Advanced Editor   Back

import { slice } from '../slice/slice';


/**
 * The find method for an array or array-like object, works in IE.
 * This method is not performant for a huge array.
 *
 * @param arrayLike - An array-like object.
 * @param predicate - The predicate function to test each element in the object.
 *
 * @return A found value if available, or otherwise `undefined`.
 */
export function find<T>(
  arrayLike: ArrayLike<T>,
  predicate: ( value: T, index: number, array: T[] ) => any
): T | undefined {
  return slice( arrayLike ).filter( predicate )[ 0 ];
}