lab19: init
This commit is contained in:
17
lab19/withProb.js
Normal file
17
lab19/withProb.js
Normal file
@@ -0,0 +1,17 @@
|
||||
function withProb(prob, f) {
|
||||
if (Math.random() < prob) {
|
||||
return f();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function foo(x) {
|
||||
withProb(0.5, function() {
|
||||
console.log("Execution withProb callback");
|
||||
return 0;
|
||||
});
|
||||
return x;
|
||||
}
|
||||
|
||||
console.log("Foo is " + foo(1));
|
||||
|
||||
Reference in New Issue
Block a user