Use function declaration syntax so sortedLettersInWord can be defined at the top, rather than intermingled with function declarations. Do case-insensitive comparison for same-word check.