LS: #2724
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```typescript []
type JSONValue = null | boolean | number | string | JSONValue[] | { [key: string]: JSONValue };
type Fn = (value: JSONValue) => number

function sortBy(arr: JSONValue[], fn: Fn): JSONValue[] {
    //let sortedArr: JSONValue[] = arr.toSorted((a, b) => fn(a) - fn(b));
    let sortedArr: JSONValue[] = arr.sort((a, b) => fn(a) - fn(b));
    return sortedArr;
};
```
```javascript []
/**
 * @param {Array} arr
 * @param {Function} fn
 * @return {Array}
 */

function sortBy(arr, fn) {
    //let sortedArr = arr.toSorted((a, b) => fn(a) - fn(b));
    var sortedArr = arr.sort((a, b) => fn(a) - fn(b));
    return sortedArr;
}
```
['TypeScript', 'JavaScript']