Tell us what’s happening:
Not able to pass test. 16. analyzeTexts should correctly aggregrate results for each text,
Not sure how exactly do I aggregrate the results??
Your code so far
function isPalindrome(word) {
let wordNew = word.toLowerCase();
return wordNew.split("").reverse().join("") === wordNew;
}
function findPalindromeBreaks(words) {
const result = [];
for (let i = 0; i < words.length; i++) {
if (!isPalindrome(words[i])) {
result.push(i);
}
}
return result;
}
function findRepeatedPhrases(words, phraseLength) {
let repeatedPhrases = [];
if (phraseLength >= words.length) return repeatedPhrases;
let checkPhrase = words.slice(0, phraseLength);
repeatedPhrases.push(0);
for (let i = phraseLength; i < words.length; i++) {
const tempPhrase = (words.slice(i, i+phraseLength));
let isMatched = true;
for (let j = 0; j < tempPhrase.length; j++) {
if (tempPhrase[j] !== checkPhrase[j]) {
isMatched = false;
}
}
if (isMatched) {
repeatedPhrases.push(i);
}
}
return repeatedPhrases;
}
function analyzeTexts(texts, phraseLength) {
if (texts === []) return [];
let analyse = [];
texts.forEach(elt => {
analyse.push({
"repeatedPhrases": findRepeatedPhrases(elt, phraseLength),
"palindromeBreaks": findPalindromeBreaks(elt)
});
});
console.log(analyse);
return analyse;
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36
Challenge Information:
Build a Proofreading Tool - Build a Proofreading Tool
GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-proofreading-tool/69dd63d1dcdeccb7b39ba4c3.md at main · freeCodeCamp/freeCodeCamp · GitHub
dhess
May 24, 2026, 3:21pm
2
Hi @chaotic.stardust ,
Please test your code by calling your functions.
For example:
console.log(analyzeTexts(["the", "cat", "sat", "the", "cat"],2))
console.log(analyzeTexts(["racecar","level","hello","level"],2))
Are these function calls returning what you expect?
Maybe you need to call the functions used in analyzeTexts to make sure they are working as expected.
Happy coding!
Isn’t the input for analyzeTexts() function an array of arrays? So I wrote the code accordingly. Should I change it for single array inputs?
Also, all other tests are passing but only test 16 is failing.
Hi @chaotic.stardust !
I agree with dhess - testing your functions individually is a great approach.
Additionally, make sure your helper functions are returning the correct values before passing them to analyzeTexts. You can debug step by step like this:
console.log(analyzeTexts([“the”, “cat”, “sat”, “the”, “cat”], 2))
Check that each function works correctly on its own first, then test them together. Hope this helps! Happy coding!
Hi,
Yes I tested all the functions individually and all of them are passing. My only problem is with test 16. that says “analyzeTexts should correctly aggregate results for each text.”
dhess
May 24, 2026, 4:43pm
6
Define “passing”.
Does this return what is expected?
console.log(findRepeatedPhrases(["racecar", "hello", "level", "hello", "splat"],1))
dhess
May 24, 2026, 4:50pm
8
Oh? You don’t see any repeated words there?
But the ‘phraseLength’ input for findRepeatedPhrases([“racecar”, “hello”, “level”, “hello”, “splat”], 1) is ‘1’.
Doesn’t that mean only the first word in the array should be checked for repetition? And the first word is ‘racecar’.
dhess
May 24, 2026, 5:21pm
10
No. It means your function should look for a sequence of one word.
Please review User Story #3 . Here’s an excerpt:
It should return an array of all start indices where a sequence of phraseLength consecutive words appears more than once in the array
Oh but I am confused why the individual test passed if that is the case. But thank you for the explanation. I will try fixing it.