Resilient Promise Executor with Configurable Retry Logic

Write a higher-order function retryPromise(fn, retries, delay) that wraps an async function or promise-returning function and automatically retries it up to N times if it rejects. Features to implement: (1) exponential backoff between retries (delay doubles each attempt); (2) optional jitter (random small offset to avoid thundering herd); (3) a shouldRetry(error) predicate that allows the caller to decide per-error whether to retry or fail fast; (4) return the resolved value on first success or reject with the last error after all retries are exhausted; (5) support an onRetry(attempt, error) callback for logging/observability.

Examples
Input: []
Output:
Hints

Resilient Promise Executor with Configurable Retry Logic

Write a higher-order function retryPromise(fn, retries, delay) that wraps an async function or promise-returning function and automatically retries it up to N times if it rejects. Features to implement: (1) exponential backoff between retries (delay doubles each attempt); (2) optional jitter (random small offset to avoid thundering herd); (3) a shouldRetry(error) predicate that allows the caller to decide per-error whether to retry or fail fast; (4) return the resolved value on first success or reject with the last error after all retries are exhausted; (5) support an onRetry(attempt, error) callback for logging/observability.