JS_HOME_WORK/74-object-destructuring/start.js
2025-02-05 08:47:22 +01:00

37 lines
920 B
JavaScript
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/** ЗАДАЧА 74 - Деструктуризация объектов
*
* Создайте функцию "shortPerson", которая деструктуризирует объект
* и возвращает его короткую версию
*
* Пример результата:
* { n: "Mike", c: "Spain", a: 23, p: 100 }
*
* Если входной объект не имеет поля postsQuantity,
* он должен получить значение по умолчанию 0
*/
const person1 = {
name: 'Mike',
info: {
country: 'Spain',
age: 23,
},
postsQuantity: 100,
}
const person2 = {
name: 'Alice',
info: {
country: 'Italy',
age: 25,
},
}
// Напишите функцию "shortPerson" здесь
console.log(shortPerson(person1))
// { n: "Mike", c: "Spain", a: 23, p: 100 }
console.log(shortPerson(person2))
// { n: "Alice", c: "Italy", a: 25, p: 0 }