Skip to content

Commit

Permalink
renaming Palindromes to Palindrome
Browse files Browse the repository at this point in the history
also removing one implementation, moving the one on root level to the playground to reduce the number of implementations to maintain
  • Loading branch information
flohei committed Oct 18, 2018
1 parent 9f5e81e commit 5a200e0
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 33 deletions.
38 changes: 38 additions & 0 deletions Palindromes/Palindromes.playground/Sources/Palindrome.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import Foundation

/**
Validate that a string is a plaindrome
- parameter str: The string to validate
- returns: `true` if string is plaindrome, `false` if string is not
*/
func isPalindrome(_ str: String) -> Bool {
let strippedString = str.replacingOccurrences(of: "\\W", with: "", options: .regularExpression, range: nil)
let length = strippedString.count

if length > 1 {
return palindrome(strippedString.lowercased(), left: 0, right: length - 1)
}
return false
}

/**
Compares a strings left side character against right side character following
- parameter str: The string to compare characters of
- parameter left: Index of left side to compare, must be less than or equal to right
- parameter right: Index of right side to compare, must be greater than or equal to left
- returns: `true` if left side and right side have all been compared and they all match, `false` if a left and right aren't equal
*/
private func palindrome(_ str: String, left: Int, right: Int) -> Bool {
if left >= right {
return true
}

let lhs = str[str.index(str.startIndex, offsetBy: left)]
let rhs = str[str.index(str.startIndex, offsetBy: right)]

if lhs != rhs {
return false
}

return palindrome(str, left: left + 1, right: right - 1)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Foundation

func isPalindrome(_ str: String) -> Bool {
let strippedString = str.replacingOccurrences(of: "\\W", with: "", options: .regularExpression, range: nil)
let length = strippedString.characters.count
let length = strippedString.count

if length > 1 {
return palindrome(strippedString.lowercased(), left: 0, right: length - 1)
Expand Down
26 changes: 0 additions & 26 deletions Palindromes/Test/Palindromes.swift

This file was deleted.

16 changes: 10 additions & 6 deletions Palindromes/Test/Test.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

/* Begin PBXBuildFile section */
9437D8841E0D960A00A38FB8 /* Test.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9437D8831E0D960A00A38FB8 /* Test.swift */; };
9437D88B1E0D969500A38FB8 /* Palindromes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9437D8791E0D948A00A38FB8 /* Palindromes.swift */; };
9437D88B1E0D969500A38FB8 /* Palindrome.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9437D8791E0D948A00A38FB8 /* Palindrome.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
9437D8791E0D948A00A38FB8 /* Palindromes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Palindromes.swift; sourceTree = "<group>"; };
9437D8791E0D948A00A38FB8 /* Palindrome.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Palindrome.swift; sourceTree = "<group>"; };
9437D8811E0D960A00A38FB8 /* Test.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Test.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
9437D8831E0D960A00A38FB8 /* Test.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Test.swift; sourceTree = "<group>"; };
9437D8851E0D960A00A38FB8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand All @@ -32,7 +32,7 @@
9437D8651E0D945200A38FB8 = {
isa = PBXGroup;
children = (
9437D8791E0D948A00A38FB8 /* Palindromes.swift */,
9437D8791E0D948A00A38FB8 /* Palindrome.swift */,
9437D8821E0D960A00A38FB8 /* Test */,
9437D86F1E0D945200A38FB8 /* Products */,
);
Expand Down Expand Up @@ -87,6 +87,7 @@
TargetAttributes = {
9437D8801E0D960A00A38FB8 = {
CreatedOnToolsVersion = 8.2;
LastSwiftMigration = 1000;
ProvisioningStyle = Automatic;
};
};
Expand Down Expand Up @@ -123,7 +124,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
9437D88B1E0D969500A38FB8 /* Palindromes.swift in Sources */,
9437D88B1E0D969500A38FB8 /* Palindrome.swift in Sources */,
9437D8841E0D960A00A38FB8 /* Test.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -229,7 +230,8 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.2;
};
name = Debug;
};
Expand All @@ -243,7 +245,8 @@
PRODUCT_BUNDLE_IDENTIFIER = self.edu.Test;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.2;
};
name = Release;
};
Expand All @@ -266,6 +269,7 @@
9437D8881E0D960A00A38FB8 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>

0 comments on commit 5a200e0

Please sign in to comment.