Skip to content

Instantly share code, notes, and snippets.

@joelibaceta
Last active April 19, 2017 14:54
Show Gist options
  • Save joelibaceta/3423a2b3e4eee92b12ad67e585c4ebff to your computer and use it in GitHub Desktop.
Save joelibaceta/3423a2b3e4eee92b12ad67e585c4ebff to your computer and use it in GitHub Desktop.
def table_for(string, hash)
hash.map{|k,v| string.scan(/(?=#{k.to_s})/).count == v}.all?
end
# irb(main):005:0> table_for("un lagarto no es un perro, un lagarto es un lagarto", {"lagarto"=> 3, "perro"=> 1})
# => true
# irb(main):006:0> table_for("un lagarto no es un perro, un lagarto es un lagarto", {"lagarto"=> 3, "perro"=> 2})
# => false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment