From: Albert Schlef Date: 2013-06-09T21:10:47+09:00 Subject: Re: How do I write a method, which returns whether the letters in a word occur in alphabetical order 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/.