diff --git a/5-arrays-and-sets/palindrome/Palindrome_with_bonus.swift b/5-arrays-and-sets/palindrome/Palindrome_with_bonus.swift new file mode 100644 index 0000000..39dc49f --- /dev/null +++ b/5-arrays-and-sets/palindrome/Palindrome_with_bonus.swift @@ -0,0 +1,29 @@ +var text: [String] = ["a", "n", "n", "a", "x"] +var reversed = [String]() +var counter = text.count - 1 + +// Using a while loop +while counter >= 0 { + reversed.append(text[counter]) + counter -= 1 +} + +/* +BONUS + +// Using stride() +for item in stride(from: counter, to: -1, by: -1) { + reversed.append(text[item]) +} + +// Using a for...in loop +for index in (0..