So this question is a just a smaller portion of a bigger problem. But it all boils down to my misunderstanding of this function..
Given my function:
func diamond(_ size: Int) -> String {
var diamonds = ""
for diamond in 0...size {
if diamond % 2 == 1 || diamond == 1 {
diamonds.append(String(repeating: "*", count: diamond))
diamonds.append("\n")
}
}
print(diamonds)
print("This should print one row less but doesn't\n", diamonds.dropLast())
diamonds = diamonds + diamonds.dropLast().reversed()
return diamonds
}
diamond(5)
The expected output for diamond(5) should be =
*
***
*****
***
*
But current output is:
*
***
*****
***** //<-- Doubled
***
*
How am I misusing dropLast? Thanks