开发者_如何学运维I think that the question title explains itself :) Suppose that i have the the numbers 1,2,3,4 and 5. Now, i have a list [1,3,4].
What is the best way to get back the inverted list ? A list like [2,5] with the missing elements ?
As simple as
> [1,2,3,4,5] - [1,3,4]
=> [2, 5]
Documentation here.
Use the splat operator to create an array from your range of numbers and then subtract out the set
> [*1..5]-[1,3,4]
=> [2, 5]
精彩评论