Created
October 14, 2018 19:08
-
-
Save ivangodfather/d970fc93e43b7ead1a97ba475b4bfdef to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import UIKit | |
| func mergeStrings(a: String, b: String) -> String { | |
| var mergedString = "" | |
| let longString = a.count > b.count ? a : b | |
| let shortString = a == longString ? b : a | |
| for (indexShortString, character) in shortString.enumerated() { | |
| mergedString += "\(character)" | |
| let indexLongString = longString.index(longString.startIndex, offsetBy: indexShortString) | |
| mergedString += "\(longString[indexLongString])" | |
| } | |
| let remainingCharactersCount = longString.count - shortString.count | |
| print(remainingCharactersCount) | |
| let remainingCharactersIndex = longString.index(longString.endIndex, offsetBy: -remainingCharactersCount) | |
| return mergedString + longString[remainingCharactersIndex...] | |
| } | |
| mergeStrings(a: "abc", b: "12345678") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment