How to return values from functions - Swift for Complete Beginners
HTML-код
- Опубликовано: 4 сен 2024
- Other videos in the Functions section:
1. How to reuse code with functions: • How to reuse code with...
2. How to return values from functions: This video
3. How to return multiple values from functions: • How to return multiple...
4. How to customize parameter labels: • How to customize param...
5. How to provide default values for parameters: • How to provide default...
6. How to handle errors in functions: • How to handle errors i...
7. Summary: Functions: • Summary: Functions - S...
8. Checkpoint 4: • Checkpoint 4 - Swift f...
You can find the full set of videos, along with transcriptions, challenges, tests, and more, in my free 100 Days of SwiftUI course: www.hackingwit...
Watch the full Swift for Complete Beginners playlist here: • Swift for Complete Beg...
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")
func checkString(string1: String, string2: String) -> Bool {
return string1.sorted() == string2.sorted()
}
let wording = checkString(string1: "word", string2: "drown")
print(wording)
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!
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!
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.
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