Build a Proofreading Tool - Build a Proofreading Tool

Tell us what’s happening:

I am not able to pass step 16. It says analyzeTexts should correctly aggregate results for each text.
I tried to log some examples and it works fine.
I am not able to figure out what im doing wrong.

Your code so far

function isPalindrome(word) {
  let palin = []
  let result = true;
  for (let i = 0; i < word.length; i++) {
    palin.push(word[i]);
  }
  let copy = [...palin];
  copy.reverse();
  for (let i = 0; i < copy.length; i++) {
    if (palin[i].toLowerCase() !== copy[i].toLowerCase()) {
      result = false;
    }
  }
  return result;
}

function findPalindromeBreaks(words) {
  let result = [];
  for (const palin of words) {
    let check = isPalindrome(palin);
    if (check === false) {
      result.push(words.indexOf(palin));
    }
  }
  return result;
}

function findRepeatedPhrases(words, phraseLength) {
  let phrase = [];
  let result = [];
  for (let i = 0; i < (words.length - phraseLength +1); i++) {
    let phra = words.slice(i, i + phraseLength);
    phrase.push(phra.join(""));
    for (let j = 0; j < phrase.length; j++) {
        if (phrase[i] === phrase[j] && i !== j) {
          result.push(j);
        result.push(i);
      }
    }
   }
  return result;
}

console.log(findRepeatedPhrases(["the", "cat", "sat", "the", "cat"],2))

function analyzeTexts(texts, phraseLength) {
  let objArr = [];
  for (const words of texts) {
    let repPhr = findRepeatedPhrases(words, phraseLength);
    let palBrek = findPalindromeBreaks(words);
    let obj = {
      repeatedPhrases: repPhr,
      palindromeBreaks: palBrek
    }
    objArr.push(obj);
  }
  return objArr;
}


console.log(analyzeTexts([["racecar", "hello", "level", "hello"]], 1));

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) 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

Welcome to the forum @BHAT_AAQIB!

Test this please:

console.log(findPalindromeBreaks(["racecar", "hello", "level", "hello"]));

Happy coding!

It logs this.

[ 1, 1 ]

I guess my code i need to change this so it can return the correct index of the repeating words which are not palindromes. Is it?

Yes, that’s correct.

Thanks it worked.

removed by moderator

Congratulations on solving the challenge! You should be proud of your achievement…we are! But we are removing your working solution, so it is not available to others who have not yet done the work to get there. Again, congrats!