Printing minimum in each iteration print the value if output is not equal to current value ( to avoid the duplicates )
if ( output != next [ toincrement ] ) { output = next [ toincrement ] ; document . write ( next [ toincrement ] + " " ) ; i ++ ; }