Getting the most frequent value of an array
<p>I have an Array of numbers and I want to know which number is most frequent in this array. The array sometimes has 5-6 integers, sometimes it has 10-12, sometimes even more - also the integers in the array can be different. So I need a function which can work with different lengths and values of an array.</p>

<p>One example:</p>

<pre><code>myArray = [0, 0, 0, 1, 1]
</code></pre>

<p>Another example:</p>

<pre><code>myArray = [4, 4, 4, 3, 3, 3, 4, 6, 6, 5, 5, 2]
</code></pre>

<p>Now I am searching for a function which gives out 0 (in the first example) as <code>Integer</code>, as it is 3 times in this array and the other integer in the array (1) is only 2 times in the array. Or for the second example it would be 4.</p>

<p>It seems pretty simple, but I cannot find a solution for this. Found some examples in the web, where the solution is to work with dictionaries or where the solution is simple - but I cannot use it with Swift 3 it seems...</p>

<p>However, I did not find a solution which works for me. Someone has an idea how to get the most frequent integer in an array of integers?</p>