2724. Sort By -  Space complexity: O(1)
Intuition\nThe problem involves sorting an array based on the values returned by a given function. The goal is to achieve ascending order according to the funct
# Intuition\nThe problem involves sorting an array based on the values returned by a given function. The goal is to achieve ascending order according to the function outputs.\n\n# Approach\nThe approach directly uses the `sort()` method on the input array, providing a custom comparison function. This comparison function compares the values returned by the provided function (`fn`) for each element. The sorting is done in place, modifying the original array.\n\n# Complexity\n- Time complexity: O(n * log(n))\n  - The `sort()` method has a time complexity of O(n * log(n)) in the worst case.\n- Space complexity: O(1)\n  - The sorting is done in place, and no additional space is used other than the input array.\n\n# Code\n```javascript\n/**\n * @param {Array} arr\n * @param {Function} fn\n * @return {Array}\n */\nvar sortBy = function(arr, fn) {\n    arr.sort((a, b) => {\n        return fn(a) - fn(b);\n    });\n    return arr;\n};\n```
['JavaScript']