Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Execute Ruby Online

# @param {String} s
# @param {String} t
# @return {Boolean}
def is_anagram(s, t)
    hash = Hash.new(0)
    hash1 = Hash.new(0)
    s.each_char do |v|
        hash.store(v, hash[v]+1)
    end
    t.each_char do |v|
        hash1.store(v, hash1[v]+1)
    end
    p hash == hash1
end

is_anagram("rat","cat")

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.