// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
// This module is browser compatible.
/**
 * Associates each element of an array with a value returned by a selector
 * function.
 *
 * If any of two pairs would have the same value the latest on will be used
 * (overriding the ones before it).
 *
 * @template T The type of the values returned by the selector function.
 *
 * @param array The array of elements to associate with values.
 * @param selector The selector function that returns a value for each element.
 *
 * @returns An object where each element of the array is associated with a value
 * returned by the selector function.
 *
 * @example Basic usage
 * ```ts
 * import { associateWith } from "@std/collections/associate-with";
 * import { assertEquals } from "@std/assert/assert-equals";
 *
 * const names = ["Kim", "Lara", "Jonathan"];
 *
 * const namesToLength = associateWith(names, (person) => person.length);
 *
 * assertEquals(namesToLength, {
 *   "Kim": 3,
 *   "Lara": 4,
 *   "Jonathan": 8,
 * });
 * ```
 */ export function associateWith(array, selector) {
  const result = {};
  for (const element of array){
    result[element] = selector(element);
  }
  return result;
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImh0dHBzOi8vanNyLmlvL0BzdGQvY29sbGVjdGlvbnMvMC4yMjQuMi9hc3NvY2lhdGVfd2l0aC50cyJdLCJzb3VyY2VzQ29udGVudCI6WyIvLyBDb3B5cmlnaHQgMjAxOC0yMDI0IHRoZSBEZW5vIGF1dGhvcnMuIEFsbCByaWdodHMgcmVzZXJ2ZWQuIE1JVCBsaWNlbnNlLlxuLy8gVGhpcyBtb2R1bGUgaXMgYnJvd3NlciBjb21wYXRpYmxlLlxuXG4vKipcbiAqIEFzc29jaWF0ZXMgZWFjaCBlbGVtZW50IG9mIGFuIGFycmF5IHdpdGggYSB2YWx1ZSByZXR1cm5lZCBieSBhIHNlbGVjdG9yXG4gKiBmdW5jdGlvbi5cbiAqXG4gKiBJZiBhbnkgb2YgdHdvIHBhaXJzIHdvdWxkIGhhdmUgdGhlIHNhbWUgdmFsdWUgdGhlIGxhdGVzdCBvbiB3aWxsIGJlIHVzZWRcbiAqIChvdmVycmlkaW5nIHRoZSBvbmVzIGJlZm9y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