Build a Proofreading Tool - Build a Proofreading Tool

Tell us what’s happening:

My analyzeText method is not working not only because I am confused on how to interpret the request but because of my findRepeatedPhrases not exactly working well with analyzeText. Although my findRepeatedPhrases, passes all check within its own checkbox criteria, it is likely causing issues with the analyzeTexts.

Your code so far

function isPalindrome(word)
{
  let count = 0
  for(let i = 1; i <= word.length; i++){
    if(word[i-1].toLowerCase() === word[word.length-i].toLowerCase())
    {
      count++
      console.log(count)
      if(count == word.length){return true}
      
    }
    else return false
  }
}

function findPalindromeBreaks(words)
{
  let countMissingPals = []
  if(words == "")
  {
    return []
  }
  for(let i = 0; i < words.length; i++)
  {
    if(!isPalindrome(words[i]))
    {
      countMissingPals.push(i)
    }
  }
  return countMissingPals
}

function findRepeatedPhrases(words, phraseLength)
{
  let moreThanOnce = []
  let result = []
  if(phraseLength >= words.length){return []}
  for(let i = 0; i < words.length; i++)
  {
    if(moreThanOnce.includes(words[i]))
    {
      console.log(i + " index of word appearing more than once")
      console.log(moreThanOnce.indexOf(words[i]) + " earlier appearance")
      if(result.length == 0)
      {
        result.push(moreThanOnce.indexOf(words[i]))
        //console.log(moreThanOnce[])
        //console.log(result)
      }
      if(result.length > 0 && words[i] == moreThanOnce[0])
      {
        result.push(i)
        //console.log(result)
      }
    console.log(words[i] + " is repeatedWord")
    }
    moreThanOnce.push(words[i])
    //for(let j = 0; j < moreThanOnce)
  }
  return result
  console.log(moreThanOnce + " array")
}

function analyzeTexts(texts, phraseLength)
{
  if(texts.length == 0)
  {
    return []
  }
  const obj = {
      repeatedPhrases: findRepeatedPhrases(words, phraseLength),
      palindromeBreaks: findPalindromeBreaks(words)
    };
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:150.0) Gecko/20100101 Firefox/150.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

Hi @d3911ready,

Test your code by calling your function:

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

This generates an error in the console:

ReferenceError: words is not defined

Also, what does analyzeTexts return?

Happy coding!

analyze text needs to return an array of objects with the two properties repeatedPhrases and palindromeBreaks as mentioned. However mine are all empty arrays. It looks like I am missing something to better understand what it is that I am missing. Here is my updated function:

function analyzeTexts(texts, phraseLength)

{

const resultArr = []

if(texts.length == 0)

{

return \[\]

}

for(let words of texts)

{

resultArr.push({repeatedPhrases : findRepeatedPhrases(words,phraseLength),

palindromeBreaks : findPalindromeBreaks(words),

}) 

}

return resultArr

}

I am stuck on step 16. 1-15 and 17 are all cleared

Please post all of your code so it can be tested, and format it as follows:

There are two ways you can format your code to make it easier to read and test:

  1. After you copy/paste your code into the editor, select it by dragging your cursor over it then click the (</>) button in the toolbar to automatically wrap your code in backticks. (You can click on the animated demo image below to enlarge it.)

  1. Manually add three backticks on a new line above your code and on a new line after your code. Note that a backtick is NOT the same as a single quote('). To find the backtick key on your keyboard, see this post.

To see changes to your post as you make them, you can click the (M+) button on the toolbar to bring up the rich text editor:

function isPalindrome(word)
{
  let count = 0
  for(let i = 1; i <= word.length; i++){
    if(word[i-1].toLowerCase() === word[word.length-i].toLowerCase())
    {
      count++
      console.log(count)
      if(count == word.length){return true}
      
    }
    else return false
  }
}

function findPalindromeBreaks(words)
{
  let countMissingPals = []
  if(words == "")
  {
    return []
  }
  for(let i = 0; i < words.length; i++)
  {
    if(!isPalindrome(words[i]))
    {
      countMissingPals.push(i)
    }
  }
  return countMissingPals
}

function findRepeatedPhrases(words, phraseLength)
{
  let moreThanOnce = []
  let result = []
  if(phraseLength >= words.length){return []}
  for(let i = 0; i < words.length; i++)
  {
    if(moreThanOnce.includes(words[i]))
    {
      if(result.length == 0)
      {
        result.push(moreThanOnce.indexOf(words[i]))
      }
      if(result.length > 0 && words[i] == moreThanOnce[0])
      {
        result.push(i)
      }
    }
    moreThanOnce.push(words[i])
  }
  return result
}

function analyzeTexts(texts, phraseLength)
{
  const resultArr = []
  if(texts.length == 0)
  {
    return []
  }

  for(let words of texts)
  {
    resultArr.push({repeatedPhrases : findRepeatedPhrases(words,phraseLength),
    palindromeBreaks : findPalindromeBreaks(words),
    }) 
  }
  return resultArr
}

Does this function call return what you expect?

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