Skip to content

Instantly share code, notes, and snippets.

@TimBlock
Created January 22, 2016 09:39
Show Gist options
  • Save TimBlock/92dfb8b3df7a7feb5bea to your computer and use it in GitHub Desktop.
Save TimBlock/92dfb8b3df7a7feb5bea to your computer and use it in GitHub Desktop.
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