Ruby - Enumerable - collect

  • + 0 comments

    def rot13(secret_messages)

    return secret_messages.map {|d| 
        ans = ""
        for i in(0...d.length)
            ans.insert(i,helper(d[i]))
        end
        ans
        }
    

    end

    def helper(ch) alpb = "abcdefghijklmnopqrstuvwxyz" i = ch.downcase.ord - 'a'.ord return i > 25 || i < 0 ? ch : ch.ord >= 65 && ch.ord <=90 ? alpb[(i + 13)%26].upcase : alpb[(i + 13)%26] end