examples/operators/operator-example.js
function binaryExpression(first, ops, rest) {
  if (associativity[ops[0]] === 'L') {
    const applyLeft = (x, y) => new BinaryExpression(x, ops.shift(), y);
    return [first].concat(rest).reduce(applyLeft);
  } else {
    const applyRight = (x, y) => new BinaryExpression(y, ops.pop(), x);
    return [first].concat(rest).reduceRight(applyRight);
  }
}
function binaryExpression(first, ops, rest) {
  if (associativity[ops[0]] === 'L') {
    const applyLeft = (x, y) => new BinaryExpression(x, ops.shift(), y);
    return [first].concat(rest).reduce(applyLeft);
  } else {
    const applyRight = (x, y) => new BinaryExpression(y, ops.pop(), x);
    return [first].concat(rest).reduceRight(applyRight);
  }
}
function binaryExpression ( first , ops , rest ) { if ( associativity [ ops [ 0 ] ] === 'L' ) { const applyLeft = ( x , y ) => new BinaryExpression ( x , ops . shift ( ) , y ) ; return [ first ] . concat ( rest ) . reduce ( applyLeft ) ; } else { const applyRight = ( x , y ) => new BinaryExpression ( y , ops . pop ( ) , x ) ; return [ first ] . concat ( rest ) . reduceRight ( applyRight ) ; } }
We know that all lists will have ops at the same precedence levels.
We know that all lists will have ops at the same precedence levels .