Test if an array contains a specific number/string.

This commit is contained in:
ChenL
2017-03-16 10:05:50 +08:00
parent f1d68409b1
commit e4056a79ee
2 changed files with 9 additions and 1 deletions
+7 -1
View File
@@ -5,7 +5,13 @@ var operators = {
'<': (l, r) => l < r,
'>=': (l, r) => l >= r,
'<=': (l, r) => l <= r,
'contains': (l, r) => typeof l === 'string' ? l.indexOf(r) > -1 : false,
'contains': (l, r) => {
return typeof l !== 'undefined'
? typeof l.indexOf === 'function'
? l.indexOf(r) > -1
: false
: false;
},
'and': (l, r) => l && r,
'or': (l, r) => l || r
};
+2
View File
@@ -45,6 +45,8 @@ describe('expression', function() {
expect(evalExp('x contains "X"', scope)).to.equal(true);
expect(evalExp('1 contains "x"', scope)).to.equal(false);
expect(evalExp('y contains "x"', scope)).to.equal(false);
expect(evalExp('(1..5) contains 3', scope)).to.equal(true);
expect(evalExp('(1..5) contains 6', scope)).to.equal(false);
expect(evalExp('"<=" == "<="', scope)).to.equal(true);
});