Last active
December 15, 2018 06:27
-
-
Save divs1210/e9390bc7f6394c9f903b96a053667229 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ordered_infix(*nums_and_ops) | |
initial_val = nums_and_ops[0] | |
op_num_pairs = nums_and_ops.drop(1).each_slice(2).to_a | |
op_num_pairs.reduce(initial_val) do |accumulator, op_num_pair| | |
op, num = op_num_pair | |
accumulator.send(op, num) | |
end | |
end | |
ordered_infix 10, '/', 2, '-', 1, '*', 2 | |
# => 8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment