In this demo, we will talk about function in Swift. Let's talk about it. Enjoy :)
Your Code Challenge:
In this code challenge, we will leverage yesterday Code Challenge to create some awesome functions!
Create a new playground called 7DSC-Day4-MinMaxFunctions
Create a new function called generate random numbers that takes in an Int called upper, the number of random numbers we want to generate called count - an Int and return an array of Int.
Test the new function by calling it to generate 10 random numbers less than 987.
Now, time to create the min function to find the minimum number of an array of integers. Create a function called get min that takes an array of integers called nums and return a value of type that you should determine by yourself :)
Implement this function. Remember the rule of finding a min / max number! Here it is if you forgot about it 😋 RULE: do not use any other Swift function like min, max to find the number. You have to use a for loop here! And do not use any other functions to sort the array. You have to use for loop! Otherwise there is no point of practicing loop :( This is in red so you know that I'm seriously serious here! 😈
Test this new getMin function with the array from step 3 now.
And hey, have fun doing this!
Share your awesome Code Challenge solution below in the comment section, leave me any questions you have, subscribe to the Youtube channel so we can connect!
Good luck and bring the joy,
-Duc
Get this swift course: https://www.ductran.co/
For more videos: https://www.youtube.com/channel/UCvPFGq6luCqAVGiFpzTvkIA/videos
Hi! I am a robot. I just upvoted you! I found similar content that readers might be interested in:
https://www.youtube.com/watch?v=o31Dmmo8mss
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit