//Функция должна вернуть массив customerId (в порядке убывания суммы всех заказов),
//содержащий не более topN клиентов, у которых есть хотя бы один завершенный заказ;
interface Order {
customerId: string;
amount: number;
status: 'pending' | 'completed';
}
const orders: Order[] = [
{ customerId: 'A', amount: 100, status: 'completed' },
{ customerId: 'B', amount: 200, status: 'completed' },
{ customerId: 'A', amount: 300, status: 'completed' },
{ customerId: 'C', amount: 400, status: 'pending' },
{ customerId: 'B', amount: 400, status: 'pending' },
];
const getSumOfCustomers = (orders: Order[], topN: number) => {
const completedOrders = orders.filter(order => order.status === 'completed');
console.log(completedOrders);
};
getSumOfCustomers(orders, 5);
Code will run automatically after changes.
Code runs in an isolated environment.
Code runs in an isolated environment.