Refactoring anagram in scala