rework of anagram in scala