Sorting lists of words using arrays