Skip to main content
const f = a => {
    const g = x => x[x.length - 1]; const b = {'+':1, '-':1, '*':2, '/':2}; let c = [];
    return a.split('').reduce((a, d) => {
        if (parseFloat(d)) a.push(d);
        if (d in b) { while (g(c) in b && b[d] <= b[g(c)]) a.push(c.pop()); c.push(d); }
        if (d == '(') c.push(d);
        if (d == ')') { while (g(c) != '(') a.push(c.pop()); c.pop();}
        return a; }, []).concat(c.reverse()).join('');
};

Code gut. Alles gut.

Leave a Reply