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