.toSorted() method
\n\n# Approach\nMethod toSorted() and sort() work about the same \n\nBut method toSorted(), unlike method sort(), returns a new array when sorting\n\n\n\n# Code
\n\n# Approach\nMethod toSorted() and sort() work about the same \n\nBut method **toSorted()**, unlike method sort(), returns a **new array when sorting**\n\n\n\n# Code\n```javascript []\n/**\n * @param {Array} arr\n * @param {Function} fn\n * @return {Array}\n */\nvar sortBy = (arr, fn) => arr.toSorted( (a,b) => fn(a) - fn(b) )\n```
['JavaScript']