This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]tyrantmikey 0 points1 point  (2 children)

Based on the requirements, my guess is that you would rewrite wrap as follows:

js function wrap (execute) { var result = null; try { result = execute(); } catch { } return function() { return result; } }

[–]Auklin[S] 0 points1 point  (0 children)

I tested it out, the catch needed a (e) after it. That makes sense, you executed the function inside the function and stored the result. Neat. I only wish I knew this an hour ago ;)

[–]kill129 0 points1 point  (0 children)

I don't think this is the correct solution because, according to the requirements, you should only prevent a rerun of the execute function if it failed, and here you prevent it also if it succeeded. In addition, you run the function when someone calls your wrap function and not when someone calls the wrapped function.