MCPcopy Create free account
hub / github.com/cn-docs/vueuse / useArrayFindLast

Function useArrayFindLast

packages/shared/useArrayFindLast/index.ts:23–34  ·  view source on GitHub ↗
(
  list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>,
  fn: (element: T, index: number, array: MaybeRefOrGetter<T>[]) => boolean,
)

Source from the content-addressed store, hash-verified

21 * @returns the last element in the array that satisfies the provided testing function. Otherwise, undefined is returned.
22 */
23export function useArrayFindLast<T>(
24 list: MaybeRefOrGetter<MaybeRefOrGetter<T>[]>,
25 fn: (element: T, index: number, array: MaybeRefOrGetter<T>[]) => boolean,
26): ComputedRef<T | undefined> {
27 return computed(() =>
28 toValue<T | undefined>(
29 !Array.prototype.findLast
30 ? findLast(toValue(list), (element, index, array) => fn(toValue(element), index, array))
31 : toValue(list)
32 .findLast((element, index, array) => fn(toValue(element), index, array)),
33 ))
34}

Callers 1

index.test.tsFile · 0.90

Calls 2

findLastFunction · 0.85
fnFunction · 0.85

Tested by

no test coverage detected