JSFiddle - React, Tailwind, and code Playground

by gkucmierz

HTML

<div class="dupa">
</div>

JavaScript

document.getElementsByClassName('dupa')[0].innerHTML = (str => {
	let op = {
  	'*': (a, b) => a * b,
  	'/': (a, b) => a / b,
  	'+': (a, b) => a + b,
  	'-': (a, b) => a - b
  };
	return ['\\*\\/', '\\+\\-'].reduce((str, ops) => {
  	let last;
    console.log(str);
		while (last !== str) {
    	last = str;
      str = str.replace(new RegExp('(\\d+)\\s(['+ops+'])\\s(\\d+)', 'g'), (...m) => {
      	console.log(m);
        return op[m[2]](m[1], m[3]) | 0;
      });
    }
    return str;
  }, str);
})('12 / 34 + 234 * 123 * 7 - 34');