randRange( 1, 10 ) randRangeExclude( 1, 10, [ FIRST ] ) randFromArray( [ [ "+", "addition", "addends" ], [ "\\times", "multiplication", "factors" ] ] ) binop( 1 )
randRange( 0, 1 ) ANSWER_INDEX ? SECOND : FIRST ANSWER_INDEX ? FIRST: SYMBOL ANSWER_INDEX ? SYMBOL: SECOND OP === "+" ? FIRST + SECOND : FIRST * SECOND

What number could replace SYMBOL below?

FIRST OP SECOND = FAKE_SECOND OP FAKE_FIRST

ANSWER

With OP_WORD, the order of the two ADDENDS does not matter.

Evaluating the left side:

FIRST OP SECOND = RESULT

Re-ordering the ADDENDS and evaluating:

SECOND OP FIRST = RESULT

We see that re-ordering the ADDENDS did not affect the final result:

FIRST OP SECOND = SECOND OP FIRST

Comparing with the original equation, the symbol SYMBOL could be replaced with the number ANSWER.

This fact about OP_WORD is known as the commutative property.

randRangeExclude( 1, 10, [ FIRST, SECOND ] ) randFromArray( [ [ "(", ")", "", "" ] ]) shuffle( [ FIRST, SECOND, THIRD ] ) randRange( 0, 2 ) (function() { var fake = TERMS.slice( 0 ); fake[ SWAP_INDEX ] = SYMBOL; return fake; })() TERMS[ SWAP_INDEX ] OP === "+" ? TERMS[ 0 ] + TERMS[ 1 ] : TERMS[ 0 ] * TERMS[ 1 ] OP === "+" ? TERMS[ 1 ] + TERMS[ 2 ] : TERMS[ 1 ] * TERMS[ 2 ] OP === "+" ? TERMS[ 0 ] + TERMS[ 1 ] + TERMS[ 2 ] : TERMS[ 0 ] * TERMS[ 1 ] * TERMS[ 2 ]

What number could replace SYMBOL below?

FIRST_OPENTERMS[ 0 ] OPSECOND_OPENTERMS[ 1 ]FIRST_CLOSE OPTERMS[ 2 ]SECOND_CLOSE = SECOND_OPENFAKE_TERMS[ 0 ] OPFIRST_OPENFAKE_TERMS[ 1 ]SECOND_CLOSE OPFAKE_TERMS[ 2 ]FIRST_CLOSE

ANSWER

With OP_WORD, the parentheses around the ADDENDS do not affect the final result.

Evaluating the left side:

FIRST_OPENTERMS[ 0 ] OPSECOND_OPENTERMS[ 1 ]FIRST_CLOSE OPTERMS[ 2 ]SECOND_CLOSE = FIRST_OPEN === "(" ? FIRST_PAIR : TERMS[ 0 ] OP FIRST_OPEN === "(" ? TERMS[ 2 ] : SECOND_PAIR = FINAL_RESULT

Changing the grouping and evaluating:

SECOND_OPENTERMS[ 0 ] OPFIRST_OPENTERMS[ 1 ]SECOND_CLOSE OPTERMS[ 2 ]FIRST_CLOSE = SECOND_OPEN === "(" ? FIRST_PAIR : TERMS[ 0 ] OP SECOND_OPEN ==="(" ? TERMS[ 2 ] : SECOND_PAIR = FINAL_RESULT

We see that moving the parentheses did not affect the final result:

FIRST_OPENTERMS[ 0 ] OPSECOND_OPENTERMS[ 1 ]FIRST_CLOSE OPTERMS[ 2 ]SECOND_CLOSE = SECOND_OPENTERMS[ 0 ] OPFIRST_OPENTERMS[ 1 ]SECOND_CLOSE OPTERMS[ 2 ]FIRST_CLOSE

Comparing with the original equation, the symbol SYMBOL could be replaced with the number ANSWER.

This fact about OP_WORD is known as the associative property.