Last active
September 3, 2018 14:21
-
-
Save NeilsUltimateLab/ccc9f7903bff340710bf6f1381f05e71 to your computer and use it in GitHub Desktop.
Find String Initials separated by space.
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 Foundation | |
| extension String { | |
| var initials: String { | |
| let split = self | |
| .split(separator: " ") | |
| .prefix(2) | |
| .compactMap { $0.first } | |
| .compactMap { String($0).uppercased() } | |
| let initials = split.joined(separator: "") | |
| return initials | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment