Live Planet interview question

Convert an array of increasing values to a compressed string version. For example [1,2,3,5,8] -> "1-3,5,8"