← All Exercises

Route Notifications Through a Fallback Chain

basicjavascript~20min

Background

Notification pipelines fail silently when a channel degrades. Explicit escalation makes the delivered channel part of the audit trail.

Problem

For each notification, keep the primary channel when it succeeded and escalate to the next channel in the fallback chain when it failed.

Input

JSON object: { notifications: [{ id, channel, ok }], fallbackChain: string[] }

Output

JSON array of { id, deliveredVia, escalated }

Sample tests

Sample 1

Input: {"notifications":[{"id":"n1","channel":"email","ok":true},{"id":"n2","channel":"email","ok":false}],"fallbackChain":["email","sms","pager"]}
Expected: [{"id":"n1","deliveredVia":"email","escalated":false},{"id":"n2","deliveredVia":"sms","escalated":true}]

Sample 2

Input: {"notifications":[{"id":"n3","channel":"pager","ok":false}],"fallbackChain":["email","sms","pager"]}
Expected: [{"id":"n3","deliveredVia":"email","escalated":true}]

Your solution

Learning objective

Design a delivery path that cannot silently drop an alert.