Easy Explanation
Explanation:Built-in Sort:The sort() function in JavaScript allows sorting elements based on a comparison function.
The comparison function (a, b) => fn(a) - fn
# Explanation:
### Built-in Sort:

The sort() function in JavaScript allows sorting elements based on a comparison function.
The comparison function (a, b) => fn(a) - fn(b) computes the difference between the results of fn applied to a and b.
### Behavior:

If fn(a) < fn(b), the function returns a negative value, indicating that a should come before b.
If fn(a) > fn(b), the function returns a positive value, indicating that a should come after b.
If fn(a) === fn(b), it returns 0, meaning their order is unchanged.

# Code
```javascript []
/**
 * @param {Array} arr
 * @param {Function} fn
 * @return {Array}
 */
var sortBy = function(arr, fn) {
    return arr.sort((a, b) => fn(a) - fn(b));
};
```
['JavaScript']