The function seems to work correctly for most inputs, but it produces some unexpected outputs for inputs with multiple consecutive letters that are not in alphabetical order. For example, the input "happy" becomes "hbpy" instead of "hppy".
