refactored invertWord() with a simpler one-liner without any import