I have an array of numbers, and I want to know which number is most often found in this array. An array sometimes has 5-6 integers, sometimes it has 10-12, and sometimes more - integers in an array can be different. Therefore, I need a function that can work with different lengths and values of the array.
One example:
myArray = [0, 0, 0, 1, 1]
Another example:
myArray = [4, 4, 4, 3, 3, 3, 4, 6, 6, 5, 5, 2]
Now I am looking for a function that returns 0 (in the first example) as Integer
, since it has 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 will be 4.
It seems pretty simple, but I can't find a solution for this. Found some examples on the Internet where the solution should work with dictionaries or where the solution is simple - but I can not use it with Swift 3, it seems ...
However, I did not find a solution that works for me. Does anyone have an idea how to get the most frequent integer in an array of integers?
Thanks guys.