Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "intersects" operator to JEXL #406

Closed
czosel opened this issue Apr 30, 2019 · 3 comments · Fixed by #408
Closed

Add "intersects" operator to JEXL #406

czosel opened this issue Apr 30, 2019 · 3 comments · Fixed by #408
Assignees

Comments

@czosel
Copy link
Contributor

czosel commented Apr 30, 2019

This would help with checking if a MultipleChoice question has at least one of the given options checked, which is a common use-case:

"my-multiple-choice-question"|answer intersects ["answer-a", "answer-b"]

JS Implementation:

questionJexl.addBinaryOp("intersects", 20, (left, right) => left.find(val => right.includes(val)))
@czosel
Copy link
Contributor Author

czosel commented Apr 30, 2019

/cc @winged @kaldras

@winged
Copy link
Contributor

winged commented Apr 30, 2019

I like the idea! However the JS implementation is a bit buggy - what if we're dealing with a falsy value so the intersects operator "succeeds" but then returns the falsy bit? some() seems to be better suited.

questionJexl.addBinaryOp("intersects", 20, (left, right) => left.some(val => right.includes(val)))

@czosel
Copy link
Contributor Author

czosel commented Apr 30, 2019

Absolutely, good catch! I've hacked this line in a bit of a rush yesterday 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants