Sort By Function
Intuition\nThe task is to sort an array based on a given function\'s return values. This involves mapping each item to its sort value using the function fn and 
## Intuition\nThe task is to sort an array based on a given function\'s return values. This involves mapping each item to its sort value using the function `fn` and then sorting based on these values.\n\n## Approach\n1. **Map the Items**: Use `map` to transform each item according to the function `fn`.\n2. **Sort**: Use `sort` to arrange the items in ascending order based on the values returned by `fn`.\n\n## Complexity\n- **Time complexity**: Sorting has a complexity of \\(O(n \\log n)\\), where \\(n\\) is the length of the array. Mapping the items to their transformed values has \\(O(n)\\) complexity, so the overall complexity is dominated by sorting: \\(O(n \\log n)\\).\n- **Space complexity**: \\(O(n)\\), due to the additional space needed to store the transformed array.\n\n## Code\n\n```javascript\n/**\n * @param {Array} arr\n * @param {Function} fn\n * @return {Array}\n */\nvar sortBy = function(arr, fn) {\n    return arr.slice().sort((a, b) => fn(a) - fn(b));\n};\n
['JavaScript']