Skip to content

Instantly share code, notes, and snippets.

@ericlmartinezo
Last active October 15, 2019 22:53
Show Gist options
  • Save ericlmartinezo/3591f8a982ec4b160703d25e6bb2c2df to your computer and use it in GitHub Desktop.
Save ericlmartinezo/3591f8a982ec4b160703d25e6bb2c2df to your computer and use it in GitHub Desktop.
Here's a stupid code paring test
// 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