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
// callback-nested | |
Database.connect("db",function(db){ | |
db.open("table",function(table){ | |
table.select("name",function(val){ | |
console.log(val); | |
}); | |
}); | |
}); | |
// un-nested |
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
//Poisson distribution | |
//http://en.wikipedia.org/wiki/Poisson_distribution | |
function poisson(expectvalue){ | |
var n = 0, //循环计数 | |
limit = Math.exp(-expectvalue), // e -v, 其中v是期望值 | |
x = Math.random(); //生成 0-1之间随机数 | |
while(x > limit){ |
NewerOlder