From 19be986696d66a6d22d3eb78c459fd4cc1e7e8ce Mon Sep 17 00:00:00 2001 From: Sergey Kosovsky Date: Thu, 14 Dec 2023 21:59:38 +0300 Subject: [PATCH] Add new solution for cw-indexed-capitaliztion --- cw-indexed-capitaliztion/main.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cw-indexed-capitaliztion/main.go b/cw-indexed-capitaliztion/main.go index 6ddc8ee..9d9cfb3 100644 --- a/cw-indexed-capitaliztion/main.go +++ b/cw-indexed-capitaliztion/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "strings" "unicode" ) @@ -32,3 +33,14 @@ func Capitalize(st string, arr []int) string { return string(newline) } + +func CapitalizeELegant(st string, arr []int) string { + res := strings.Split(st, "") + for _, v := range arr { + if v >= len(res) { + continue + } + res[v] = strings.ToUpper(res[v]) + } + return strings.Join(res, "") +}