Suppose we have a list of string numbers all_digits
and want to use the last n
digits. We can use a handy shorthand to achieve this:
all_digits = %w(1 6 1 8)
n = 2
last_digits = all_digits[-n..-1] # => ["1", "8"]
Suppose we have a list of string numbers all_digits
and want to use the last n
digits. We can use a handy shorthand to achieve this:
all_digits = %w(1 6 1 8)
n = 2
last_digits = all_digits[-n..-1] # => ["1", "8"]