2860. Sort By
My accepted JavaScript solution to LeetCode problem 2860, Sort By, running in 107ms.
- Difficulty: Easy
- JavaScript
- Runtime 107ms
- Memory 69.8MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
JavaScript
Accepted on LeetCode — runtime 107ms, memory 69.8MB, accepted 2025-12-31.
/**
* @param {Array} arr
* @param {Function} fn
* @return {Array}
*/
var sortBy = function(arr, fn) {
return arr.sort((a, b) => fn(a) - fn(b));
};