source: node_modules/es-toolkit/dist/map/findKey.d.ts

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 1.1 KB
RevLine 
[a762898]1/**
2 * Finds the first key in a Map for which the predicate function returns true.
3 *
4 * This function iterates through the entries of the Map and returns the key of the first
5 * entry for which the predicate function returns true. If no entry satisfies the predicate,
6 * it returns undefined.
7 *
8 * @template K - The type of keys in the Map.
9 * @template V - The type of values in the Map.
10 * @param {Map<K, V>} map - The Map to search.
11 * @param {(value: V, key: K, map: Map<K, V>) => boolean} doesMatch - A predicate function that tests each entry.
12 * @returns {K | undefined} The key of the first entry that satisfies the predicate, or undefined if none found.
13 *
14 * @example
15 * const map = new Map([
16 * ['apple', { color: 'red', quantity: 10 }],
17 * ['banana', { color: 'yellow', quantity: 5 }],
18 * ['grape', { color: 'purple', quantity: 15 }]
19 * ]);
20 * const result = findKey(map, (value) => value.quantity > 10);
21 * // result will be: 'grape'
22 */
23declare function findKey<K, V>(map: Map<K, V>, doesMatch: (value: V, key: K, map: Map<K, V>) => boolean): K | undefined;
24
25export { findKey };
Note: See TracBrowser for help on using the repository browser.