Ruby - Enumerable - collect

Sort by

recency

|

97 Discussions

|

  • + 0 comments
    def rot13(secret_messages)
        secret_messages.map do |str|
            str.chars.map{|char| char.ord.between?(65,90) || char.ord.between?(97,122) ? cipher(char) : char }.join
        end
    end
    
    def cipher(char)
        13.times {char.next!}
        return char.size > 1 ? char[1] : char
    end
    
  • + 0 comments
    def rot13(secret_messages)
      secret_messages.map do |string|
        string.chars.map { |c| c.ord < 97 || c.ord > 122 ? c : c.ord + 13 > 122 ? (c.ord - 13).chr : (c.ord + 13).chr }.join
      end
    end
    
  • + 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

  • + 0 comments
    def tranf(letra)
      return letra unless letra.match?(/[A-Za-z]/)
    
      offset = letra.upcase == letra ? 'A'.ord : 'a'.ord
      ((letra.ord - offset + 13) % 26 + offset).chr
    end
    
    def rot13(secret_messages)
      secret_messages.map { |message| message.each_char.map { |c| tranf(c) }.join }
    end
    
  • + 0 comments

    Hey! It’s very helpful information for Eco Cleanse. Thanks’ you! For sharing this information.