JSFiddle - React, Tailwind, and code Playground
by Alexey Demin
JavaScript
var isCanceled = false;
while (!isCanceled) {
var cmd = prompt("Enter you command:");
if (cmd === null || cmd === "") {
isCanceled = true;
continue;
}
var matches = cmd.trim().match(/([a-z]+)\(([^)]*)\)/);
var name = matches[1];
var args = matches[2]
.split(',')
.map(function(arg){
return arg.trim();
});
switch(name){
case 'plus':
var res = args
.reduce(function(sum, current){
return sum + parseFloat(current);
}, 0);
console.log(res);
break;
}
console.log(cmd);
}