// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.
/**
 * Transforms the given array into a Record, extracting the key of each element using the given selector.
 * If the selector produces the same key for multiple elements, the latest one will be used (overriding the
 * ones before it).
 *
 * Example:
 *
 * ```ts
 * import { associateBy } from "https://deno.land/std@$STD_VERSION/collections/associate_by.ts"
 * import { assertEquals } from "https://deno.land/std@$STD_VERSION/testing/asserts.ts";
 *
 * const users = [
 *     { id: 'a2e', userName: 'Anna' },
 *     { id: '5f8', userName: 'Arnold' },
 *     { id: 'd2c', userName: 'Kim' },
 * ]
 * const usersById = associateBy(users, it => it.id)
 *
 * assertEquals(usersById, {
 *     'a2e': { id: 'a2e', userName: 'Anna' },
 *     '5f8': { id: '5f8', userName: 'Arnold' },
 *     'd2c': { id: 'd2c', userName: 'Kim' },
 * })
 * ```
 */ export function associateBy(array, selector) {
    const ret = {};
    for (const element of array){
        const selectedValue = selector(element);
        ret[selectedValue] = element;
    }
    return ret;
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImh0dHBzOi8vZGVuby5sYW5kL3N0ZEAwLjE2Ni4wL2NvbGxlY3Rpb25zL2Fzc29jaWF0ZV9ieS50cyJdLCJzb3VyY2VzQ29udGVudCI6WyIvLyBDb3B5cmlnaHQgMjAxOC0yMDIyIHRoZSBEZW5vIGF1dGhvcnMuIEFsbCByaWdodHMgcmVzZXJ2ZWQuIE1JVCBsaWNlbnNlLlxuLy8gVGhpcyBtb2R1bGUgaXMgYnJvd3NlciBjb21wYXRpYmxlLlxuXG4vKipcbiAqIFRyYW5zZm9ybXMgdGhlIGdpdmVuIGFycmF5IGludG8gYSBSZWNvcmQsIGV4dHJhY3RpbmcgdGhlIGtleSBvZiBlYWNoIGVsZW1lbnQgdXNpbmcgdGhlIGdpdmVuIHNlbGVjdG9yLlxuICogSWYgdGhlIHNlbGVjdG9yIHByb2R1Y2VzIHRoZSBzYW1lIGtleSBmb3IgbXVsdGlw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