This is a bit of a hack, but one way would be to use the Scratch feature. Untested example:
{{ range $i, $v := .Params.versions }}
{{ with $v.id }}{{ $.Scratch.SetInMap "ids" . . }}{{ end }}
{{ end }}
{{ delimit ($.Scratch.GetSortedMapValues "ids") ", " }}