How do I write a method, which returns whether the letters in a word occur in alphabetical order

How do I write a method, which returns whether the letters in a word
occur in alphabetical order?

Thank you

···

--
Posted via http://www.ruby-forum.com/.

You start by thinking of a good name for the method and the argument. Once
you have the name you write "def name(arg) end". Now you think of an
algorithm to solve your problem. Write it between ")" and "end". Do some
testing. Done.

robert

···

On Sat, Jun 8, 2013 at 4:31 AM, Tario C. <lists@ruby-forum.com> wrote:

How do I write a method, which returns whether the letters in a word
occur in alphabetical order?

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Hi Robert,

Is there a reference directory of algorithms? How do I know the
functionality of every algorithm?

Thank you

···

--
Posted via http://www.ruby-forum.com/.

Tario C. wrote in post #1111683:

How do I write a method, which returns whether the letters in a word
occur in alphabetical order?

Tip: you can use recursion -- check only the first two characters of the
string, then ask your function to check the rest.

(It won't really be efficient in Ruby, because strings aren't lists, but
it'd be cute. (On the other hand, splicing a string in Ruby perhaps uses
copy-on-write so it may not be inefficient.))

···

--
Posted via http://www.ruby-forum.com/\.

Hi
good question and similar to a previous one posed here
for a method to count the consonants in a text or a speech
a regular expression was the basis of a solution in that example

···

On Sun, Jun 9, 2013 at 9:57 AM, Tario C. <lists@ruby-forum.com> wrote:

Hi Robert,

Is there a reference directory of algorithms? How do I know the
functionality of every algorithm?

Thank you

--
Posted via http://www.ruby-forum.com/\.

Albert Schlef wrote in post #1111786:

Tario C. wrote in post #1111683:

How do I write a method, which returns whether the letters in a word
occur in alphabetical order?

Tip: you can use recursion -- check only the first two characters of the
string, then ask your function to check the rest.

(It won't really be efficient in Ruby, because strings aren't lists, but
it'd be cute. (On the other hand, splicing a string in Ruby perhaps uses
copy-on-write so it may not be inefficient.))

Well, let me "correct" myself, just for the record: even if splicing a
string copies their content unconditionally, it wouldn't be horrible
since (1) our code is intended for "word"s, which are relatively short;
and (2) this is a scripting language and the copying, done in C, is
negligible.

BTW (and sorry if it's somewhat off-topic), Bjarne Stroustrup favors
vectors
over linked lists: http://www.youtube.com/watch?v=YQs6IC-vgmo

···

--
Posted via http://www.ruby-forum.com/\.

Well, let me "correct" myself, just for the record: even if splicing a
string copies their content unconditionally, it wouldn't be horrible
since (1) our code is intended for "word"s, which are relatively short;

How do you know? That's just an assumption.

and (2) this is a scripting language and the copying, done in C, is
negligible.

Depends on how often you do it. And, btw. often the expensive part isn't
the copying but the memory management (GC bookkeeping and collection).

Cheers

robert

···

On Sun, Jun 9, 2013 at 2:10 PM, Albert Schlef <lists@ruby-forum.com> wrote:

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/