Alphabetical Order
tags: character-comparison array-traversal
Check if an array of strings is in alphabetical order.
Implementation
The current character can be compared with the preceding character:
|
|
In the implementation the starting index is 1 and the ending index is n-1. The current characters can be compared with the next character:
|
|
In this alternative implementation the starting index is 0 and the end index is n-2. In Ruby both the implementations work for string as well as array input.