Problem statement
Write function solution(orders). Inputs and outputs are JSON values. Do not modify input arrays or objects. External libraries, network access, and asynchronous functions are not supported. orders is an array of {category:string,amount:nonnegative integer,status:string}. Count only orders with status exactly paid. Trim category; use uncategorized for a blank category. Categories are case-sensitive. Return {category,count,total} objects sorted by total descending, with ties sorted by category ascending using JavaScript string comparison. Input limits: at most 50,000 items per input array and 1,000 characters per string. Numbers are finite; integers and accumulated integer results stay in the JavaScript safe-integer range. Other types and validity rules follow the statement above.
Example input and output
Example 1
Function arguments
[
[
{
"category": "food",
"amount": 10,
"status": "paid"
},
{
"category": "food",
"amount": 20,
"status": "paid"
}
]
]Return value
[
{
"category": "food",
"count": 2,
"total": 30
}
]Example 2
Function arguments
[
[
{
"category": "b",
"amount": 10,
"status": "paid"
},
{
"category": "a",
"amount": 10,
"status": "paid"
}
]
]Return value
[
{
"category": "a",
"count": 1,
"total": 10
},
{
"category": "b",
"count": 1,
"total": 10
}
]Example 3
Function arguments
[
[
{
"category": "a",
"amount": 1,
"status": "paid"
},
{
"category": "b",
"amount": 100,
"status": "paid"
},
{
"category": "a",
"amount": 200,
"status": "paid"
}
]
]Return value
[
{
"category": "a",
"count": 2,
"total": 201
},
{
"category": "b",
"count": 1,
"total": 100
}
]