Is it possible to avoid messing with duplicate array elements when you're messing with the first one?
Consider the following:
def rot13(str)
alphabet = ("a".."z").to_a
letters = str.split("").each{|x| x.downcase! }
letters.map! do |let|
alphabet[(alphabet.index(let) + 13) % alphabet.length]
end
#werd = letters.join("")
letters.map.with_index do |char,index|
str.each_char.with_index do |c,idx|
if str[idx].upcase! == nil
letters.at(idx).upcase!
end
end
end
#werd
letters
end
rot13("ANdrea")
This is just a Ceaser Cypher fixed at 13 letters over. Straightforward until we hit the duplicate "a"
s, which turns into duplicate "n"
s after the code runs. As it is here, the upcase!
loop upcases in letters
everything that was at those indexes in the original string, and I only need those indexes to be capitalized. How do I isolate that?