12345678910111213141516171819202122232425262728293031323334353637383940 |
- module.exports = compile;
- var BaseFuncs = require("boolbase"),
- trueFunc = BaseFuncs.trueFunc,
- falseFunc = BaseFuncs.falseFunc;
- function compile(parsed){
- var a = parsed[0],
- b = parsed[1] - 1;
-
-
- if(b < 0 && a <= 0) return falseFunc;
-
- if(a ===-1) return function(pos){ return pos <= b; };
- if(a === 0) return function(pos){ return pos === b; };
-
- if(a === 1) return b < 0 ? trueFunc : function(pos){ return pos >= b; };
-
- var bMod = b % a;
- if(bMod < 0) bMod += a;
- if(a > 1){
- return function(pos){
- return pos >= b && pos % a === bMod;
- };
- }
- a *= -1;
- return function(pos){
- return pos <= b && pos % a === bMod;
- };
- }
|