Tell us what’s happening:
I’m struggling to see what exactly is wrong with my code. By all accounts it should be working.
Your code so far
function purgeMostFrequent(arr) {
//I can't think of a more efficient way to do this without using a hashmap to store the word and it's occurences
let map = new Map();
for(let i = 0; i < arr.length; i++){
let occurences = 0;
for(let j = 0; j < arr.length; j++){
if(arr[i] == arr[j]){
occurences++;
}
}
map.set(arr[i], occurences);
}
//now find which one has the highest value
let maxKey = null;
let maxValue = -Infinity; // Initialize with negative infinity so any value is greater
for (const [key, value] of myMap) {
if (value > maxValue) {
maxValue = value;
maxKey = key;
}
}
let mostFrequentElement = map.get(maxKey);
//remove the most frequently occuring element
let filteredArr = arr.filter(item => item !== mostFrequentElement);
console.log(filteredArr)
return filteredArr;
}
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36
Challenge Information:
Daily Coding Challenge - Purge Most Frequent
https://www.freecodecamp.org/learn/daily-coding-challenge/2025-12-20