Mode entretien. Minuteur de 5 min, sans indices ni autocomplétion
Close in finally
FacileErrors5 min
Write a function useResource(log, work). First it adds the string 'open' to the array log, then it calls work() and returns its result. At the end 'close' always goes into log, even when work() throws. Do not swallow that error, let it go on as it is.
Exemples
useResource([], () => 42)Renvoie 42
(() => { const log = []; useResource(log, () => 'done'); return log; })()Renvoie [ 'open', 'close' ]
Chargement de l'éditeur...
- Returns the result of work, log has open and close
- The error from work goes on, and close is in log
Les tests cachés se lancent à la soumission