Here is a dumb version, that wastes loads of memory.

func reverse(in string) string {
   out := strings.Builder{}
   out.Grow(len(in))
   runes:= make([]rune, 0, len(in))


   for _, r := range in {
      runes = append(runes, r)
   }
   for i := len(runes) -1; i >= 0; i-- {
      out.WriteRune(runes[i])
   }
   return out.String()
}




On Saturday, 15 February 2020 16:37:15 UTC, Amarjeet Anand wrote:
>
> Hi
>
> I was wondering why isn't there built-in string reverse function. Is it 
> left intentionally because of some reason?
>
> Although strings are immutable in go, there are multiple ways to achieve 
> this pretty easily. But having this function inbuilt will save our time 
> because we need it quite often.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/cae39c11-f492-4890-b0ff-332d2e51042b%40googlegroups.com.

Reply via email to