Define your custom JavaScript operators - Star on
Github
Define your operators
/* * How to add a new operator? * ---------------------------------------------------------- * Choose a character that can be converted in an operator * (e.g. '⋂') add it as key in `operators` object below. The * value must be an object containing `name` key that * indicates what function is called. Then declare your * function indicated in `name` key. * * Below you have an example about how to create `⋂` operator. * */ operators = { "⋂": { name: "Intersection", }, "★": { name: "Star", } }; Intersection = function (x, y) { var c = []; for (var i in x) { if (y.indexOf(x[i]) !== -1) { c.push(x[i]); } } return c; }; Star = function (x, y) { if (typeof x !== "string" || typeof y !== "string") throw new Error("Arguments must be strings."); return x + y; };
Run your JavaScript code containing your operators
/* * This is basically a JavaScript code that will return a value * when it will be run. * * You can use the operators created by you. * See the example below. * */ var x = [1, 2, 3, 4, 5] , y = [3, 5, 6, 1]; console.log("Having two arrays: x = " + JSON.stringify(x) + " and y = " + JSON.stringify(y) + " x ⋂ y will be " + JSON.stringify(x ⋂ y)); console.log("If" ★ " you" ★ " like" ★ " this," ★ " STAR" ★ " this" ★ " on" ★ " Github" ★ " now! ;-)");
Run
Output
/* * Press the RUN button and you will see here the output. * */