Monday, October 3
Shadow

Reverse letter in strin. Don’t move the position of non letters

# ab-cd
#=> dc-ba

#j>*Zz
#=> z>*Zj

s = "j>*zZ"
s = s.chars
j = s.length - 1
i = 0


while i < j 
    if s[i].match?(/[a-zA-Z]/) && s[j].match?(/[a-zA-Z]/)
        s[i], s[j] = s[j], s[i]
    end
    i += 1 
    j -= 1
end

p s.join('')

Leave a Reply