From: "Haris Bogdanoviæ" Date: 2009-07-12T02:05:05+09:00 Subject: Re: one line sorting In general, how do I combine collect, inject and detect in one line of code to create functional expressions ? "Haris Bogdanovi�" wrote in message news:h39ttc$279$1@gregory.bnet.hr... > Hi. > > I would like to implement a sorting algorithm in one line of code if > possible. > > n=[7,4,9,55,98,11,42] > n.inject(n[0]) {|min, i| min=i if i > I first find lowest number in list and then would like to replace it with > first element. After that I need to start from the second element, find > the lowest element, replace it with that second element and so on till I > reach the end of a list. > I don't know how this sorting algorithm is called ? > > I managed to find the minimum in the above code. What next ? How to > replace two elements ? > The result is a number object. Where do I (in general) put a dot in above > expression to perform some methods on that object (when expression has a > block {} of code in itself ) ? > > Can you also show me that for a quick sort ? > > Thanks > Haris >