How do you define custom hash for strings in ruby? -


i hash strings in ruby characters in each string without order, example want anagrams have same hash value.

is possible?

how about:

require 'digest'  string = "mysupersamplestring" sorted = string.chars.sort.join  p sorted # => => "msssaeegilmnpprrtuy"  digest::md5.hexdigest(sorted) # => "ef86bea3ade82ae7bf0409952bc83fd7" 
  • chars "splits" string letters
  • sort sorts letters array
  • join joins array of letters 1 string

hope helps!


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -