Q: Lua: string: evaluate if characters are in ascending order How can if evaluate whether all characters composing a string are in strictly ascending/descending order?
eg:
print(is_strictly_asc_or_desc("abcdefghijklmnopqrstuvwxyz")) --> true
print(is_strictly_asc_or_desc("abba")) --> false
print(is_strictly_asc_or_desc("dj")) --> true
print(is_strictly_asc_or_desc("ace")) --> true
print(is_strictly_asc_or_desc("cent")) --> true
print(is_strictly_asc_or_desc("foot")) --> true
print(is_strictly_asc_or_desc("old")) --> true
print(is_strictly_asc_or_desc("file")) --> false
print(is_strictly_asc_or_desc("")) --> true
print(is_strictly_asc_or_desc("b")) --> true

I tried something (but it is not working, and even if fixed, I doubt that it will be efficient...):
function is_strictly_asc_or_desc(s)
    local alphabet = {a=1,b=2,c=3,d=4,e=5,f=6,g=7,h=8,i=9,j=10,k=11,l=12,m=13,n=14,o=15,p=16,q=17,r=18,s=19,t=20,u=21,v=22,w=23,x=24,y=25,z=26}
    if alphabet[s[1]] < alphabet[s[2]] then
        for i,letter in ipairs(s) do
            if alphabet[s[i]] > alphabet[s[i+1]] then
                return false
            end
        end
    else
        for i,letter in ipairs(s) do
            if alphabet[s[i]] < alphabet[s[i+1]] then
                return false
            end
        end
    end
    return true
end

We can assume words are solely constructed from chars in "abcdefghijklmnopqrstuvwxyz" IE only lower case letters; EG: "abc!f" --> invalid; "Hello" --> invalid; etc. 

A: To solve this we can iterate over the string and check their byte values!
function Validate(str,asc)
    local temp = asc and 0 or math.huge
    local temp2
    for i = 1,#str do
        temp2 = str:sub(i,i):byte()
        if (ask and temp2 < temp) or temp2 < temp then
            return false
        else
            temp = temp2
        end
    end
    return true
end

EDIT: Fixed function to accept optional ascending argument, this allows you to determine if it's ascending to descending separately. I feel this is more powerful since you can use it in different situations.

A: A similar variation for either ascending or descending:
function is_strictly_asc_or_desc(s)
  while #s > 2 and s:sub(2,2) == s:sub(1,1) do s = s:sub(2) end
  local temp = s:sub(1,1)
  local up = s:sub(2,2) > temp
  for c = 2, #s do
    c = s:sub(c,c)
    if up and c < temp or not up and c > temp then return false end
    temp = c
  end
  return true
end

