freeCodeCamp Challenge Guide: Sort an array of composite structures

Sort an array of composite structures


Solutions

Solution 1 (Click to Show/Hide)
function sortByKey (arr) {
  return arr.sort(function(a, b) {
    return a.key - b.key
  });
}