Beats 96.11%‼ You also could do this!
IntuitionWe can use the Array.sort and use the fn paramater to get the value that we want to compare.Approach
This is ascending sort, so we expect element n is
# Intuition
We can use the Array.sort and use the `fn` paramater to get the value that we want to compare.

# Approach
- This is ascending sort, so we expect `element n` is lesser than `element n+1` by substract `element n` by `element n+1` in the body function of Array.sort.

# Complexity
- Time complexity:
O(n)

- Space complexity:
O(1)

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

# Result
![Screenshot 2024-12-19 at 2.40.52 PM.png](https://assets.leetcode.com/users/images/72384dee-5c3f-43c9-92f4-ac3088f788c5_1734590472.3959045.png)

['JavaScript']