1 Line solution (O(n log n))
Complexity\n- Time complexity: O(n log n).\n\n# Code\n\nvar sortBy = function(arr, fn) {\n    return arr.sort((a, b) => fn(a) - fn(b))\n};\n
# Complexity\n- Time complexity: O(n log n).\n\n# Code\n```\nvar sortBy = function(arr, fn) {\n    return arr.sort((a, b) => fn(a) - fn(b))\n};\n```
['JavaScript']