Single line JS with explanation (90% run time)
\n# Approach\n Describe your approach to solving the problem. \nUsing sort function in JS. \n\n# Solution\n Describe your approach to solving the problem. \nArr
\n# Approach\n<!-- Describe your approach to solving the problem. -->\nUsing sort function in JS. \n\n# Solution\n<!-- Describe your approach to solving the problem. -->\nArray.sort(compareFn) works in the following way:\ncompareFn = (a,b)=> {\n/* some logic that returns 0, 1 or -1 \n\n1. a and b are the two elements picked from arr for comparison (so a,b are always defined)\n2. if compareFn returns -1, array is sorted as [a,b]\n3. if compareFn returns +1, array is sorted as [b,a]\n4. if compareFn returns 0, order of a,b is left unchanged\n\n*/\n\n}\n\n\n# Code\n```\nfunction sortBy(arr: any[], fn: Function): any[] {\n    return arr.sort((a,b)=>fn(a)-fn(b))\n};\n```
['TypeScript']