Reference no: EM132296667
Implement the function named mode to satisfy the following requirements.
You can assume the array of numbers given to mode contains only integer values.
When mode is called with an empty array for parameter a, it should return 0.
When mode is called with a non-empty array for parameter a, it should return the element which occurs most frequently in the array a. For example, mode([0, 1, 1, 2, 2, 1, 3]) should return 1 because the number 1 occurs 3 times and no other number occurs that many times.
When an array contains multiple modes, return the smallest of the modes. For example, mode([0, 2, 2, 1, 1]) should return 1 because although both 1 and 2 are modes of this array, 1 is smaller than 2.