I like the solution to "subtract" all characters of the shorter word from the (possibly) longer word, and check if there is some character left:
importData.List(delete,sortBy)importData.Function(on)-- deletes the first character of word from strdelstrword=delete(headword)str-- deletes all chars of word from strstr`without`word=foldldelstr(map(:[])word)-- are there any remaining characters? isAnagramword1word2=null$longer`without`shorterwhere[shorter,longer]=sortBy(compare`on`length)[word1,word2]
Ok, this is more fun, but it somehow reimplemented the library function ( \ \ ) (which can be read as the difference operation in set theory)
I'm sorry, it took me a dinner out to see, this was unnecessarily complicated. :) The delete functions perfectly fits a right fold. And if the words aren't of equal length, they are not anagrams.
-- deletes the first occurance of element x from a listdelete_[]=[]deletex(y:ys)=ifx==ythenyselsey:deletexys-- deletes all elements of the second list from the firstwithout::Eqa=>[a]->[a]->[a]without=foldrdelete-- are there any remaining characters? isAnagramword1word2=null$word1`without`word2
delete could also be imported from Data.List
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I like the solution to "subtract" all characters of the shorter word from the (possibly) longer word, and check if there is some character left:
Ok, this is more fun, but it somehow reimplemented the library function ( \ \ ) (which can be read as the difference operation in set theory)
I'm sorry, it took me a dinner out to see, this was unnecessarily complicated. :) The delete functions perfectly fits a right fold. And if the words aren't of equal length, they are not anagrams.
delete could also be imported from Data.List