Tell us what’s happening:
My code is running fine on all the test cases, but I’m unable to pass test 16 and 17. I have tried everything, but I’m unable to find out the issue. Can someone please help me.
Your code so far
const isPalindrome = word => {
for(let i=0; i<word.length/2; i++) {
if(word[i].toLowerCase()!=word[word.length-i-1].toLowerCase()) return false
}
return true
}
const findPalindromeBreaks = words => {
if(!words.length) return [];
let answer = [];
for(let i=0; i<words.length; i++) {
let result = isPalindrome(words[i])
if(result == false) {
answer.push(i)
}
}
return answer
}
const findRepeatedPhrases = (words, phraseLength) => {
if(phraseLength >= words.length) return []
let repeatedPhrases = []
let phrase = []
for(let i=0; i<phraseLength; i++) {
phrase.push(words[i])
}
for(let j=phraseLength; j<words.length-1; j++) {
let newPhrase = []
for(let k=0; k<phraseLength; k++) {
newPhrase.push(words[j+k])
}
let matches = true
for(let k=0; k<phrase.length; k++) {
if(phrase[k] !== newPhrase[k]) matches = false
}
if(matches) {
if(repeatedPhrases.length === 0) {
repeatedPhrases.push(0)
}
repeatedPhrases.push(j)
}
}
return repeatedPhrases
}
const analyzeTexts = (texts, phraseLength) => {
if(!texts.length) return []
let result = []
for(let i=0; i<texts.length; i++) {
const palindromeCount = findPalindromeBreaks(texts[i]);
const repeatedWords = findRepeatedPhrases(texts[i], phraseLength);
let textObject = {
repeatedPhrases: repeatedWords,
palindromeBreaks: palindromeCount
};
result.push(textObject);
}
return result;
}
console.log(analyzeTexts([["racecar", "hello", "level", "hello"]], 1))
let test = [
["the", "cat", "sat", "the", "cat"],
["the", "racecar", "races", "the", "racecar"],
["every", "ever", "everlasts", "every", "everlasting", "ever"]
];
console.log(analyzeTexts(test, 2));
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 Edg/148.0.0.0
Challenge Information:
Build a Proofreading Tool - Build a Proofreading Tool