[LRUG] Subtracting two arrays

Matthew Willson matthew at playlouder.com
Thu Dec 16 10:25:54 PST 2010


> [1,2,3] - [2,3]
 => [1] 

:)

On 16 Dec 2010, at 18:23, John Winters wrote:

> A quick technical question if I may.
> 
> I'm still learning Ruby and have come across something which I feel sure the standard libraries should be able to do, but I can't find an existing way to do it.
> 
> I have two arrays, one of which lists all the rooms in a school and the other of which lists all the rooms currently in use.  I want to print a list of free rooms, so essentially I need a new array consisting of all the elements of the first array which aren't in the second array.
> 
> Obviously I can hand-craft a suitable function quite easily, but I'm getting used to being able to do all these sort of things with a simple Ruby one-liner.  Does such a way exist?
> 
> TIA,
> John
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> http://lists.lrug.org/listinfo.cgi/chat-lrug.org




More information about the Chat mailing list