Remove modulus from percentage calculation

Instead take the last part of ip, divide by 256 to get percentage and
compare to percentage passed in.
This commit is contained in:
Fabien O'Carroll 2014-05-15 17:38:07 +01:00
parent a886652280
commit 846010ed6e

View File

@ -59,13 +59,8 @@ function ipAsNum(req) {
}
function percentage(n, req) {
var mod = parseInt(100 / n, 10); // ensures whole number
if (mod === 0) {
mod = 1;
}
var ip = ipAsNum(req);
return ip % mod === 0;
return (ip / 256) <= (n / 100);
}