-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
arthurwrls
committed
Oct 11, 2022
1 parent
2a25f50
commit 6f4f273
Showing
2 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
Codecademy.playground/Pages/Polindrome.xcplaygroundpage/Contents.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
var text = ["h", "e", "l", "l", "o"] | ||
var reversed = [String]() | ||
var counter = text.count - 1 | ||
|
||
while counter >= 0 { | ||
reversed.append(text[counter]) | ||
counter -= 1 | ||
|
||
} | ||
if text == reversed { | ||
print("We have a palindrome!") | ||
} else { | ||
print("We don’t have a palindrome") | ||
} | ||
|
||
/* | ||
//with for in usage | ||
|
||
var text = ["h", "e", "l", "l", "e", "h"] | ||
var reversed = [String]() | ||
var counter = text.count - 1 | ||
|
||
for x in 0 ..< text.count { | ||
if x >= 0 { | ||
reversed.append(text[counter]) | ||
counter -= 1 | ||
} | ||
} | ||
if text == reversed { | ||
print("We have a palindrome!") | ||
} else { | ||
print("We don’t have a palindrome") | ||
} | ||
|
||
|
||
//with stride usage | ||
|
||
var text = ["h", "e", "l", "l", "e"] | ||
var reversed = [String]() | ||
var counter = text.count - 1 | ||
|
||
for x in stride (from: 0, to: text.count, by: 1){ | ||
if x >= 0 { | ||
reversed.append(text[counter]) | ||
counter -= 1 | ||
} | ||
} | ||
if text == reversed { | ||
print("We have a palindrome!") | ||
} else { | ||
print("We don’t have a palindrome") | ||
} | ||
|
||
|
||
|
||
*/ |