linq.js
function toMap(keySelector, elementSelector) {
  if (!keySelector) return new Map(this);

  elementSelector = typeof elementSelector === 'function' ? elementSelector : i => i;
  let map = new Map();

  for (let item of this) {
    let key = keySelector(item);
    let element = elementSelector(item);
    map.set(key, element);
  }

  return map;
}
function toMap(keySelector, elementSelector) {
  if (!keySelector) return new Map(this);

  elementSelector = typeof elementSelector === 'function' ? elementSelector : i => i;
  let map = new Map();

  for (let item of this) {
    let key = keySelector(item);
    let element = elementSelector(item);
    map.set(key, element);
  }

  return map;
}
function toMap ( keySelector , elementSelector ) { if ( ! keySelector ) return new Map ( this ) ; elementSelector = typeof elementSelector === 'function' ? elementSelector : i => i ; let map = new Map ( ) ; for ( let item of this ) { let key = keySelector ( item ) ; let element = elementSelector ( item ) ; map . set ( key , element ) ; } return map ; }
Creates a map from a sequenece according to a specified key selector function, a comparer, and an element selector function.

@param keySelector A function to extract a key from each element.
@param elementSelector A transform function to produce a result element value from each element.
@return A map that contains values from the input sequence.
keySelector: (item) -> key (Required)
elementSelector: (item) -> value (Optional)
Creates a map from a sequenece according to a specified key selector function a comparer and an element selector function .