Build a Proofreading Tool - Build a Proofreading Tool

Tell us what’s happening:

I can’t pass tests 12, 13, 17, and 18 and I’m not sure why. It seems to work fine when I test it.

Your code so far

function isPalindrome(word) {
  const lowerCase = word.toLowerCase();
  const reversedWord = lowerCase.split("").reverse().join("");
  return reversedWord === lowerCase;
}

function findPalindromeBreaks(words) {
  const nonPals = [];
  if (words) {
    for (let i = 0; i < words.length; i++) {
      if(isPalindrome(words[i])) {
        continue;
      } else {
        nonPals.push(i);
      }
    }
  }
  return nonPals;
}

function findRepeatedPhrases(words, phraseLength) {
  const repeats = [];
  const phrases = {};
  if (phraseLength >= words.length || phraseLength === 0) {
    return repeats;
  }

  for (let i = 0; i < words.length - phraseLength + 1; i++) {
    phrases[i] = words.slice(i, i + phraseLength).join(" ").toLowerCase();
  }

  for (const phrase in phrases) {
    for (const check in phrases) {
      if (phrases[phrase] === phrases[check] && phrase != check) {
        repeats.push(phrase);
      }
    }
  }
  return repeats;
}

function analyzeTexts(texts, phraseLength) {
  const analysis = [];
    for (const words of texts) {
      const repeatedPhrases = findRepeatedPhrases(words, phraseLength);
      const palindromeBreaks = findPalindromeBreaks(words);
      const textAnalysis = {repeatedPhrases, palindromeBreaks};
      analysis.push(textAnalysis);
    }
  return analysis;
}


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:156.0) Gecko/20100101 Firefox/156.0

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

If you look at the browser’s console (not the console on page), there are some details about failing tests.

As it turns out, the integer keys in objects are coerced to string, so returned repeats contains strings, instead of integers.