Triage incidents

When several incidents arrive at once, the team scores each by impact and urgency and handles the highest priority first.

What to build

Give each incident a priority and list them in the order to handle.

Requirements

  • Each line is name impact urgency, both 1 (low) to 3 (high).
  • Score = impact × urgency. Priority: P1 for 9, P2 for 6, P3 for 3 or 4, P4 for 1 or 2.
  • Print the incidents from highest score to lowest; equal scores keep their input order. Each line: P? name (score S).

Input

One incident per line.

Output

One line per incident.

Constraints

1 to 30 incidents. Names have no spaces.

Example

Input:

phishing-click 2 3
ransomware 3 3
spam 1 1

Output:

P1 ransomware (score 9)
P2 phishing-click (score 6)
P4 spam (score 1)

Why it works

Multiplying impact by urgency ranks incidents that are both serious and spreading first, and a stable sort keeps the reporting order among equals, so the team always knows what to start on.

Examples

Example 1 · Input
phishing-click 2 3
ransomware 3 3
spam 1 1
Expected output
P1 ransomware (score 9)
P2 phishing-click (score 6)
P4 spam (score 1)
Example 2 · Input
printer-offline 1 2
laptop-stolen 2 2
Expected output
P3 laptop-stolen (score 4)
P4 printer-offline (score 2)

Hints

Hint 1

Array sort in JavaScript is stable, so sorting by score keeps the input order for ties.

Solution

Show one correct solution (try it yourself first)
const incidents = [];
let line = prompt();
while (line !== null) {
  if (line.trim()) {
    const [name, impact, urgency] = line.trim().split(/\s+/);
    incidents.push({ name, score: Number(impact) * Number(urgency) });
  }
  line = prompt();
}
const priority = (s) => (s >= 9 ? "P1" : s >= 6 ? "P2" : s >= 3 ? "P3" : "P4");
incidents.sort((a, b) => b.score - a.score);
for (const i of incidents) console.log(`${priority(i.score)} ${i.name} (score ${i.score})`);

▶ Open this solution in the compiler, then press Visualize to watch it run step by step

Lesson: Incident response basics →