From b200be550cf9da916d4633eac1b0c29c27e619cf Mon Sep 17 00:00:00 2001 From: Tomek Marchi Date: Tue, 5 Dec 2023 07:55:07 -0500 Subject: [PATCH] invokeCollection --- source/collection/invoke.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/source/collection/invoke.js b/source/collection/invoke.js index 08f0008d..73d23994 100644 --- a/source/collection/invoke.js +++ b/source/collection/invoke.js @@ -1,8 +1,9 @@ import { mapArray } from '../arrays/map.js'; +import { indexBy } from './indexBy'; /** * Invokes a function on the provided property name in each object in the collection. * - * @function invoke + * @function invokeCollection * @category collection * @type {Function} * @param {Array} collection - Collection from which method will be taken. @@ -11,10 +12,13 @@ import { mapArray } from '../arrays/map.js'; * @returns {Array} - Returns the results of the invoked method. * * @example - * invoke([{lucy(item, index) { return [item, index];}}, {lucy(item, index) { return [item, index];}}], 'lucy', 'EXAMPLE'); - * // => [['EXAMPLE', 0], ['EXAMPLE', 1]] + * import { invokeCollection, assert } from '@universalweb/acid'; + * const results = invokeCollection([{ + * test(item, index) { return [item, index];} + * }], 'test', ['EXAMPLE']); + * assert(results, [['EXAMPLE', 0]]); */ -export function invoke(collection, property, value) { +export function invokeCollection(collection, property, value) { return mapArray(collection, (item, index) => { return item[property](value, index); });