ESPAÑOL: Muy buena esa manera de una sola línea de código, cómo no lo vi antes? jaja. Yo lo hice así: func compareWords(word1: String, word2: String) -> Bool { //Declaro la función con 2 parámetros -> devuelve Bool let comparative = word1.sorted() == word2.sorted() ? true : false //Toda la condición aquí return comparative //Devuélveme lo que valga comparative } ¡Gracias por el contenido!
Sür topu, çek şutu, at golü, her gören aklına kaybedicekk Sakatsın iki ay blaketen, bu durum beni mahfedicek! Sen her gölün ayrı bi zevk, Harry Kane Harry Kane Harry Kane, Seni istiyorum hucümda her maç, bu durum beni mahvedicek! Eyy
i mostly watch through your site but had to come here and give a sub and some likes! Appreciate all this knowledge! Hope i stick with this lol
import Cocoa
func sameLetters(str1: String, str2: String) -> Bool {
if str1.sorted() == str2.sorted() {
return true
} else {
return false
}
}
sameLetters(str1: "amor", str2: "roma")
Interesting that you don't need to add an explicit return for the inner function ie. Int.random() or sqrt(). Feels weird coming from JS!
func checkString(string1: String, string2: String) -> Bool {
return string1.sorted() == string2.sorted()
}
let wording = checkString(string1: "word", string2: "drown")
print(wording)
ESPAÑOL: Muy buena esa manera de una sola línea de código, cómo no lo vi antes? jaja.
Yo lo hice así:
func compareWords(word1: String, word2: String) -> Bool { //Declaro la función con 2 parámetros -> devuelve Bool
let comparative = word1.sorted() == word2.sorted() ? true : false //Toda la condición aquí
return comparative //Devuélveme lo que valga comparative
}
¡Gracias por el contenido!
FIzzBuzz was a breeze but the identical letters-function humbled me
Single line code without return is
sqrt(a * a + b * b)
func isBothStringsSame(a: String, b:String) ->BOOL{
if a.count != b.count{return false}
else{ a.sorted() == b.sorted(){return true}
}
not working.
func containsSameLetters (firstStr: String, secondStr: String) -> Bool{
firstStr.lowercased().sorted() == secondStr.lowercased().sorted()
}
I really want to be able to learn coding. But I'm starting to be afraid I'm just too stupid :D
Fellow dummy here. Keep at it! Repetition is key.
function are really tripping me up
func areWeTwins(string1: String, string2: String) -> Bool {
return string1.lowercased().sorted() == string2.lowercased().sorted()
}
let sameOrNot = areWeTwins(string1: "IamLordVoldemort", string2: "TomMarvoloRiddle")
print (sameOrNot)
Sür topu, çek şutu, at golü, her gören aklına kaybedicekk
Sakatsın iki ay blaketen, bu durum beni mahfedicek!
Sen her gölün ayrı bi zevk, Harry Kane Harry Kane Harry Kane,
Seni istiyorum hucümda her maç, bu durum beni mahvedicek!
Eyy