function Car(color, mileage, weight, length) {
this.color = color;
this.mileage = mileage;
this.weight = weight;
this.length = length;
};
// создаем по конструктору несколько объектов
const cars = [
new Car("green", 110000, 1165, 4346),
new Car("red", 155000, 1274, 4540),
new Car("blue", 90000, 1156, 4132),
];
const carsSorted = (cars,key, reverse) => Array.from(cars).sort(({ [key]: a }, { [key]: b }) => reverse ? b - a : a - b);
console.log("cars sorted by mileage", carsSorted(cars,"mileage"));
console.log("cars sorted by weight", carsSorted(cars,"weight"));
console.log("cars sorted by length", carsSorted(cars,"length", true));