I have a list of items in an array. The default output of the items is a simple list separated by commas. However, a proper sentence would include the word \"and\"
One of the possible ways is to use functional programming:
let myArray = ["Apple", "Bee", "Carrot", "Dog"] let mapedArray = myArray.dropLast().map{ myArray.indexOf($0) == myArray.count - 2 ? $0 + " and " + myArray[myArray.count - 1] : $0 + "," }