title: Working with maps in Golang
body: <p>I am new to Go and doing a few exercises. One of them is to sort the numbers in an array by frequency, from most to least frequent. </p>
  
  <pre><code>Example: 
  Input: [2, 2, 5, 7, 4, 4, 4, 7, 2]
  Output: [2, 4, 7, 5]
  </code></pre>
  
  <p>Note that <code>[4, 2, 7, 5]</code> would also be correct, since 4 and 2 have the same frequency. </p>
  
  <p>For this purpose I am converting the array into a <strong>value value</strong> map, which here would look like this: <code>[2:3][4:3][7:2][5:1]</code> (2 and 3 have freq. of 3, 7 has the freq of 2,... )</p>
  
  <p>Afterwards I would like to simply loop through the map and output the <strong>keys</strong> ordered by <strong>value</strong>. For that I use the following code, which apparently does not work. Why? </p>
  
  <pre><code>count := 0
  max := -1
  
  // break loop, if map is empty
  for i := 0; i &lt; 1; i-- {
      if len(m) == 0 {
          break
      }
  
      max = -1
  
      // get key of biggest value
      for k, v := range m {
          if v &gt; max {
              max = k
          }
      }
      // res (for result) is a slice of integers
      res[count] = max
      // remove key-value-pair from map
      delete(m, max)
      count++
  }
  return res
  </code></pre>
  
  <p>Please keep in mind that this is an exercise. I am very sure there are much better, build in ways to do this.</p>