Ad
  • Custom User Avatar

    Hey,
    Imagine a = []int{1, 2, 5, 100} and s = "abcdef" so
    by r := []rune(s) we convert the input string to its runes (characters),
    so we have slice of characters in r, e.g. r[0]='a' and r[1]='b' and so on.
    Using for _, v := range a { iterate over indices e.g. 1, 2, 5, 100 using v.
    here if v >= 0 && v < len(r) we make sure that index v is valid index inside the slice.
    Then we convert the rune to upper case and save it in place: r[v] = unicode.ToUpper(r[v]).
    So now r = []rune{'a','B','C','d','e','F'}.
    Finally convert to string: return string(r).
    I hope this helps.