Skip to content

Instantly share code, notes, and snippets.

@Viniciuscarvalho
Created January 23, 2019 13:08
Show Gist options
  • Select an option

  • Save Viniciuscarvalho/179cb70389e480c6292584046c8f459c to your computer and use it in GitHub Desktop.

Select an option

Save Viniciuscarvalho/179cb70389e480c6292584046c8f459c to your computer and use it in GitHub Desktop.
Algoritmo de procura se a messageString tem todas as letras de message e mostra se tem ou não todas as palavras.
import UIKit
var messageString = ["a", "casa", "do", "lago", "sempre", "é", "azul"]
var message = "a casa do lago é azul"
// 1º Resolução
let checkArray = message.components(separatedBy: " ").filter { return !messageString.contains($0) }
print(checkArray.isEmpty ? "é igual": "erooou")
---------------------------------------------------------------
// 2º Resolução
//var splittedMessage = message.split(separator: " ")
//splittedMessage.forEach { (word) in
// if messageString.contains(word) {
// matches += 1
// }
//}
//print(matches)
//if matches == splittedMessage.count {
// print("é igual baby")
//} else {
// print("errou baby")
//}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment