function sortByKey(arr, keyFn, opt_compareFn) {
  const keyCompareFn = opt_compareFn || defaultCompare;
  sort(arr, function(a, b) {
    return keyCompareFn(keyFn(a), keyFn(b));
  });
}
Sort the specified array into ascending order based on item keys
returned by the specified key function.
If no opt_compareFn is specified, the keys are compared in ascending order
using <code>defaultCompare</code>.

Runtime: O(S(f(n)), where S is runtime of <code>sort</code>
and f(n) is runtime of the key function.

@param {Array<T>} arr The array to be sorted.
@param {function(T): K} keyFn Function taking array element and returning
    a key used for sorting this element.
@param {?function(K, K): number=} opt_compareFn Optional comparison function
    by which the keys are to be ordered. Should take 2 arguments to compare,
    and return a negative number, zero, or a positive number depending on
    whether the first argument is less than, equal to, or greater than the
    second.
@template T,K