Solution in Javascript with decent memory and space complexity
Complexity

Time complexity:
Sorting an array has a worst-case time complexity of
𝑂(nlogn), where n is the length of the array.


Space complexity:
Average case

# Complexity
- Time complexity:
Sorting an array has a worst-case time complexity of 
𝑂(nlogn), where n is the length of the array.

- Space complexity:
Average case: O(log n)

# 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']