DEV Community

loading...

Discussion on: Daily Challenge #124 - Middle Me

Collapse
kesprit profile image
kesprit

Swift solution :

func middleMe(x: Character, y: Character, n: Int) -> String {
    (n % 2 == 0 && n > 1) ? "\(String.init(repeating: y, count: n / 2 ))\(x)\(String.init(repeating: y, count: n / 2 ))" : String(x)
}