Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Jabor Al thani
Jabor Al thani
2,926 Points

Logic operators to sort average values in Swift?

Im going through my first project in the IOS development plan . I just wanted to know if there was a way of using logic to sort number values which are divided into 3 groups while having the average group's value with a certain number between them .

Jabor Al thani
Jabor Al thani
2,926 Points

Within * a certain number between them

4 Answers

array.map()

could you be more precise pls

show me your code

Jabor Al thani
Jabor Al thani
2,926 Points

Manually create a single collection named 'players' that contains all information for all 18 players. Each player must themselves be represented by a Dictionary with String keys and the corresponding values. Create appropriate variables and logic to sort and store players into three teams: Sharks, Dragons and Raptors. Store the players for each team in collection variables named 'teamSharks', 'teamDragons', and 'teamRaptors'. Be sure that your logic results in all teams having the same number of experienced players on each.

The above is some of the steps required from me in the project . I've got 18 players which I need to sort out using logic . I've already finished up the dictionary .

let players = [ "Joe Smith" : [ 42 , "YES","Jim and Jan Smith"], "Jill Tanner": [ 36 , "YES" , "Clara Tanner"], "Bill Bon" : [ 43, "YES" ," Sara and Jenny Bon"], "Eva Gordon" : [ 45 , "NO" , "Wendy and Mike Gordon"], "Matt Gill" : [45 , "NO" , "Charles and Sylvia Gill"], "Kimmy Stein" : [ 41 , "NO" , "Bill and Hilary Stein"], "Sammy Adams" : [ 45 , "NO" , "Jeff Adams"], "Karl Saygan" : [42 , "YES" , "Heather Bledsoe"], "Suzane Greenberg" : [44 , "YES" , "Henrletta Dumas"], "Sal Dall" : [41 , "NO" , "Gala Dall"], "Joe Kavaller" : [39 , "NO", "Sam and Elaine Kevaller"], "Ben Finkelstein" : [ 44 , "NO", "Aaron and Jill Finkelstein"], "Diego Soto" : [41 , "YES" , "Robin and Sarlka Soto"], "Chloe Alaska":[47,"NO","David and Jamie Alaska"], "Arnold Wills":[43,"NO","Claire Wills"], "Phillip Helm":[44,"YES","Thomas Helm and Eva Jones"], "Les Cay":[42,"YES","Wynonna Brown"], "Herschel Krustofski":[45,"YES","Hyman and Rachel Krustofski"]

]

Now I need to sort them out in 3 teams using logic swell as having the same amount of experienced players in the 3 teams . So should I just use "if statements" or are there better ways ?