Explorer
Node.js

Write a function `promiseFinally(promise, onFinally)` that calls `onFinally` regardless of whether the promise resolves or rejects.

Problem Statement

Write a function `promiseFinally(promise, onFinally)` that calls `onFinally` regardless of whether the promise resolves or rejects.

Complexity

Time Complexity: -

Space Complexity: -

Hints

šŸ’” Hint 1: finally runs the callback whether the promise fulfills or rejects. šŸ’” Hint 2: Chain .then() for both success and failure, calling onFinally in both. šŸ’” Hint 3: promise.then(val => { onFinally(); return val; }, err => { onFinally(); throw err; }); āœ… Solution: ```javascript function promiseFinally(promise, onFinally) { return promise.then( val => { onFinally(); return val; }, err => { onFinally(); throw err; } ); } ```

Implement Promise.finally Polyfill

Hard
Write a function `promiseFinally(promise, onFinally)` that calls `onFinally` regardless of whether the promise resolves or rejects.
Editor
Loading Editor...
Evaluate code
Output:Click "Run" above to execute and verify your code here.
{"v":42,"called":true}