Last active
October 15, 2019 22:53
-
-
Save ericlmartinezo/3591f8a982ec4b160703d25e6bb2c2df to your computer and use it in GitHub Desktop.
Here's a stupid code paring test
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
// Write a function that outputs the letters that repeats in "Hello World" | |
import Foundation | |
func letterOccuranceCount(word1: String) -> Bool { | |
let letters = word1.map { String($0) } | |
// get duplicates | |
let duplicates = Array(Set(letters.filter({ (i: String) in letters.filter({ $0 == i }).count > 1}))) | |
// remove duplicates from str | |
for item in duplicates { | |
if duplicates.count > 1 { | |
print(duplicates, item) | |
} | |
} | |
return true | |
} | |
letterOccuranceCount(word1: "Hello world!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment