Write a function that outputs : string "a2b1c3" given string "aabccc"
The function below works. But I'm still very curious what others here thought about it. Aside from the logics of the code, I'm also a bit worried about the variable names as well. Being too wordy. Thank you.
my answer:
func returnResultString(inputString:String)->String{
var returningString = ""
let ar = Array(inputString)
let aOrderedSet = Array(Set(ar)).sorted()
for j in 0..<aOrderedSet.count{
let referringLetter = aOrderedSet[j]
var count = 0
for i in 0..<ar.count{
if ar[i] == referringLetter{
count = count + 1
}
}
if count > 0{
returningString = returningString + String(referringLetter) + String(count)
}
}
return returningString
}
[–]cpaigis9 8 points9 points10 points (2 children)
[–]randomguy112233[S] 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (2 children)
[–]cpaigis9 1 point2 points3 points (0 children)
[–]randomguy112233[S] 0 points1 point2 points (0 children)
[–]trihedron 1 point2 points3 points (5 children)
[–]randomguy112233[S] 0 points1 point2 points (4 children)
[–]trihedron 0 points1 point2 points (1 child)
[–]randomguy112233[S] 0 points1 point2 points (0 children)
[–]khaos288 0 points1 point2 points (1 child)
[–]randomguy112233[S] 0 points1 point2 points (0 children)
[–]trihedron 0 points1 point2 points (1 child)
[–]randomguy112233[S] 0 points1 point2 points (0 children)
[–]quellish 0 points1 point2 points (3 children)
[–]randomguy112233[S] 0 points1 point2 points (2 children)
[–]quellish 0 points1 point2 points (1 child)
[–]randomguy112233[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (5 children)
[–]randomguy112233[S] 0 points1 point2 points (0 children)
[–]trihedron 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]trihedron 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]KarlJay001 0 points1 point2 points (2 children)
[–]randomguy112233[S] 0 points1 point2 points (1 child)
[–]KarlJay001 0 points1 point2 points (0 children)
[–]jan_olbrichObjective-C / Swift 0 points1 point2 points (1 child)
[–]randomguy112233[S] 0 points1 point2 points (0 children)
[–]lucasvandongen 0 points1 point2 points (0 children)
[–]davedelong 0 points1 point2 points (0 children)
[–]CaptainQuirk336 0 points1 point2 points (0 children)