Asynchronous order processing with timeout

TypeScript Medium async

Task «Asynchronous order processing with timeout»

Write an asynchronous function `processOrders` that takes an array of order objects (each with fields `id: number` and `delay: number`). For each order, create an asynchronous operation that executes after `delay` milliseconds (use `setTimeout`). If the operation does not complete within 1000 ms, it should be rejected with an error `'Timeout'`. The function should return an array of results in the order of the original orders: for successful ones — `{id, status: 'ok'}`, for rejected ones — `{id, status: 'timeout'}`. Use `Promise.allSettled` and a helper promise with a timeout.

Input Format

First line — number n (number of orders). Then n lines, each containing two numbers: id and delay.

Output Format

n lines, each in the format: id status (ok or timeout).

Examples

Example 1

INPUT
Hello World
OUTPUT
3

Example 2

INPUT
Hello world
OUTPUT
2

Example 3

INPUT
2 10 1200 20 800
OUTPUT
10 timeout 20 ok

Example 4

INPUT
JavaScript
OUTPUT
3
main.ts