title: Which element is most common in the array? If there is a tie, which element had a lower index in the array that was sorted
body: <p>Which element is seen the most in the array, if there is a tie, return the first element that was encountered by my user?</p>
  
  <p>I have the user picking the wind for his golf shots. So at each distance the user shoots from, a wind is picked and put into an array. The array is as follows. 0 = no wind, 1 = north, 2 = west, 3 = south, 4 = east (I used Ints for some reasons but it likely can only be attributed to my semi-beginner knowledge).
  The goal is to return the most common wind that they encountered during the round/level. If there is a tie, the first wind condition they encountered should be returned. </p>
  
  <p>The current problem in my solution is that when I iterate through the initial array and place them in a dictionary to increment the value for each key as it is seen, I have no way of knowing which order the dictionary is in, therefore I cannot return the first key-value pair in the dictionary like I was hoping for initially. My current setup can only sort ties by taking the greatest or least key between the tieing key-value pairs. In no way does that reflect the order in the myWindArray itself. </p>
  
  <p>// myWindArray basically means they took 8 shots, 0(no wind) was first shot, 1(north wind was second), ...</p>
  
  <pre><code>let myWindArray = [0,1,0,3,1]
  
  func mostCommonWind (array: [Int]) -&gt; Int {
  var dictionary: [Int: Int] = [:]
  
  // Iterate over the dictionary
  for b in array {
      // Every time there is a repeat value add one to that key
      dictionary[b] = (dictionary[b] ?? 0) + 1
  }
  let decending = dictionary.sorted(by: {$0.1 &gt; $1.1})
  return (decending[0].key)
  
  }
  </code></pre>
  
  <p>mostCommonWind returns a value of 0 like I am hoping for but it only return 0 because that key is sorted as the lower of the two between 0 and 1 keys. My intent is to return the value of 0 because it was the first value in the input array placed into the mostCommonWindfunction was a 0. Any ideas?</p>