TutorialEdge

Challenge 15 - Repeating Letters

Welcome, everyone to the discussion thread for the 15th Go challenge posted to the site :tada:

Feel free to show us how you solved the challenge by posting your solutions below!

Hi All,

Thank you Elliot for creating this amazing learning resource.
I am learning golang, and here is my solution for the problem 15.

Repeating Letters Go Playground

Thanks

1 Like

Looks good! Iā€™m glad you are enjoying the challenges :smile:

1 Like
package main

import "fmt"

func DoubleChars(original string) string {
  endString := make([]rune, 0, len(original)*2)
  for _, c := range original {
    endString = append(endString, c, c)
  }
  return string(endString)
}

func main() {
  fmt.Println("Smallest Difference Challenge")

  original := "gophers"
  doubled := DoubleChars(original)
  fmt.Println(doubled) // ggoopphheerrss
}
func DoubleChars(original string) string {
	var double []rune
	for _, k := range original {
		double = append(double, k)
		double = append(double, k)
	}
	return string(double)
}