function toMap(arr, keyFunc) {
  const /** !Map<K, V> */ map = new Map();

  for (let i = 0; i < arr.length; i++) {
    const element = arr[i];
    map.set(keyFunc(element, i, arr), element);
  }

  return map;
}
Creates a new ES6 Map built from the provided array and the key-generation
function.
@param {!IArrayLike<V>} arr Array or array like object over which to iterate
    whose elements will be the values in the new object.
@param {?function(V, number, ?) : K} keyFunc The function to call for every
    element. This function takes 3 arguments (the element, the index, and the
    array) and should return a value that will be used as the key for the
    element in the new object. If the function returns the same key for more
    than one element, the value for that key is implementation-defined.
@return {!Map<K, V>} The new map.
@template K,V