const createUser = function(name, age) {
return {
name,
age,
toString: function() {
return `${this.name} is
${this.age}y.o.`;
},
}
}
const users = [
createUser("John", 21),
createUser("Tory", 18),
createUser("Kate", 23),
createUser("Pete", 22),
]
users.sort((a,b) => a- b);
не затрагивая строчку sort
users.sort((a,b) => a- b);
valueOf() {
return this.age;
},
toString
на[Symbol.toPrimitive](hint) {
return hint === 'number'
? this.age
: `${this.name} is ${this.age} y.o.`;
},