Create your own operators in JavaScript
npm install js-custom-operators[![Support me on Patreon][badge_patreon]][patreon] [![Buy me a book][badge_amazon]][amazon] [![PayPal][badge_paypal_donate]][paypal-donations]    
> Create your own operators in JavaScript
During the Math classes we learned how to define new operators. For example:
#### (ℝ, ∘), x ∘ y = x + 2y
This defines ∘ law. For any real numbers x and y, x ∘ y is x + 2y. e.g: 2 ∘ 2 = 2 + 4 = 6.
This projects finally bring this feature in the JavaScript world! :-) Using esprima - which takes JS code and generates the syntax tree for it - and escodegen - which does the other direction, generating JS code from the syntax tree esprima spits - we can create new JavaScript operators.
Having two arrays:
``js`
var x = [1, 2, 3, 4, 5]
, y = [3, 5, 6, 1]
;
we want to find the intersection of them (that is [1, 3, 5]).
We can easily create a function function foo (x, y) { ... }, but why not create an operator instead?
Then x ⋂ y will return the same thing. :-)
You can try this application online clicking here.
There are few ways to get help:
1. Please post questions on Stack Overflow. You can open issues with questions, as long you add a link to your Stack Overflow question.
2. For bug reports and feature requests, open issues. :bug:
3. For direct and quick help, you can use Codementor. :rocket:
However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it:
- Starring and sharing the projects you like :rocket:
- [![Buy me a book][badge_amazon]][amazon]—I love books! I will remember you after years if you buy me one. :grin: :book:
- [![PayPal][badge_paypal]][paypal-donations]—You can make one-time donations via PayPal. I'll probably buy a ~~coffee~~ tea. :tea:
- [![Support me on Patreon][badge_patreon]][patreon]—Set up a recurring monthly donation and you will get interesting news about what I'm doing (things that I don't share with everyone).
- Bitcoin—You can send me bitcoins at this address (or scanning the code below): 1P9BRsmazNQcuyTxEqveUsnf5CERdq35V6`

Thanks! :heart:
- @benjamingr posted this great answer to my question on StackOverflow
- esprima
- escodegen
[MIT][license] © [Ionică Bizău][website]
[license]: /LICENSE
[website]: https://ionicabizau.net
[contributing]: /CONTRIBUTING.md
[docs]: /DOCUMENTATION.md
[badge_patreon]: https://ionicabizau.github.io/badges/patreon.svg
[badge_amazon]: https://ionicabizau.github.io/badges/amazon.svg
[badge_paypal]: https://ionicabizau.github.io/badges/paypal.svg
[badge_paypal_donate]: https://ionicabizau.github.io/badges/paypal_donate.svg
[patreon]: https://www.patreon.com/ionicabizau
[amazon]: http://amzn.eu/hRo9sIZ
[paypal-donations]: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=RVXDDLKKLQRJW