Tell us what’s happening:
Given the coding challenge description, the second test: getWords("I like coding. I like testing. I love debugging!") should return ['i', 'like'] since the word 'coding' only appears once in the given string.
So my code does not pass the tests
Your code so far
function getWords(paragraph) {
const wordToLowerCase = paragraph
.toLowerCase()
.replace(/[^\w\s\']|_/g, "")
.replace(/\s+/g, " ");
const newArr = wordToLowerCase.split(" ");
const wordCount = newArr.reduce((acc, word) => {
acc[word] = (acc[word] || 0) + 1;
return acc;
}, {});
const op = Object.entries(wordCount).sort((a, b) => b[1] - a[1]);
const flattenedArr = op.reduce((acc, curr) => {
console.log("Curr 1", curr[1]);
if (curr[1] <= 1) {
console.log("skipping", curr[0]);
return acc;
}
return acc.concat(curr[0]);
}, []);
return flattenedArr;
}
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Safari/537.36
Challenge Information:
Daily Coding Challenge - Word Frequency
https://www.freecodecamp.org/learn/daily-coding-challenge/09-14
GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/daily-coding-challenges-javascript/68b06e589bf227324381476f.md at main · freeCodeCamp/freeCodeCamp · GitHub