Create a function that takes an array and returns a new array containing the most frequently occuring elements in it.
function mostFrequentElement(arr){
// write your code here
}
console.log(mostFrequentElement([1,2,5,1,3,5,2,1])); // [1]
console.log(mostFrequentElement([1,2,5,1,3,5,2,1,2])); // [1,2]
console.log(mostFrequentElement([1,2,5,1,3,5,2,1,2,3,3])); // [1,2,3]
Please watch this video for a hint for the problem: