[{rooms: 2, square: 25},{rooms: 1, square: 10}, {rooms: 2, square: 20},{rooms: 1, square: 12}]
[{rooms: 1, square: 10}, {rooms: 1, square: 12}, {rooms: 2, square: 20},{rooms: 2, square: 25}]
arr.sort((a, b) => (a.rooms - b.rooms) || (a.square - b.square));
// или, в более общем виде
const sort = (arr, ...keys) =>
arr.sort((a, b) => {
let diff = 0;
keys.find(k => diff = a[k] - b[k]);
return diff;
});
sort(arr, 'rooms', 'square');
const sorted = (arr, keys) => arr
.map(n => [ n ].concat(keys(n)))
.sort((a, b) => {
let diff = 0;
for (let i = 0; ++i < a.length && !(diff = a[i] - b[i]);) ;
return diff;
})
.map(n => n[0]);
const sortedArr = sorted(arr, n => [ n.rooms, n.square ]);