Ruby なら、sort_by でシュオーツ変換なので高速。
sort はO(N^2)

input_fruits_ary = %w(apple, banana, nut, mangosteen)

# 文字列数の少ない順でソート
input_fruits_ary.sort_by! { |fruit| fruit.length }

p input_fruits_ary
#=> ["nut,", "apple,", "banana,", "mangosteen"]

# 文字列数の多い順でソート
input_fruits_ary.sort_by! { |fruit| fruit.length * -1 }

p input_fruits_ary
#=> ["mangosteen", "banana,", "apple,", "nut,"]