-
-
Save TimBlock/92dfb8b3df7a7feb5bea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function MultiplicatorUnitFailure() {} | |
function primitiveMultiply(a, b) { | |
if (Math.random() < 0.5) | |
return a * b; | |
else | |
throw new MultiplicatorUnitFailure(); | |
} | |
function reliableMultiply(a, b) { | |
// Your code here. | |
for(;;){ | |
try{ | |
return primitiveMultiply(a,b) | |
} | |
catch (e){ | |
if( !(e instanceof MultiplicatorUnitFailure )) | |
throw e; | |
} | |
} | |
}; | |
console.log(reliableMultiply(8, 8)); | |
// → 64 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment