fix(curriculum): add overlapping phrases test (#67553)

This commit is contained in:
Lakshay Goyal
2026-05-23 17:30:35 +05:30
committed by GitHub
parent e08b9f992f
commit 652f0e0eb2
@@ -21,7 +21,7 @@ A phrase is a sequence of consecutive words. For example, in `["the", "cat", "sa
2. You should define a function named `findPalindromeBreaks` that takes a `words` array as its argument. It should return an array of indices of words that are not palindromes. It should return an empty array if the input is empty.
3. You should define a function named `findRepeatedPhrases` that takes a `words` array and a `phraseLength` number as arguments. It should return an array of all start indices where a sequence of `phraseLength` consecutive words appears more than once in the array — including the index of the first occurrence. It should return an empty array if `phraseLength` is greater than or equal to the length of `words`.
3. You should define a function named `findRepeatedPhrases` that takes a `words` array and a `phraseLength` number as arguments. It should return an array of all start indices where a sequence of `phraseLength` consecutive words appears more than once in the array — including the index of the first occurrence. It should return an empty array if `phraseLength` is greater than or equal to the length of `words`. Overlapping sequences should also be counted.
4. You should define a function named `analyzeTexts` that takes a `texts` array and a `phraseLength` number as arguments. It should process each element of `texts` (each an array of words) and return an array of objects, each with `repeatedPhrases` and `palindromeBreaks` properties. It should return an empty array if `texts` is empty.
@@ -100,6 +100,12 @@ assert.sameDeepOrderedMembers(findRepeatedPhrases(["the"], 2), []);
assert.sameDeepOrderedMembers(findRepeatedPhrases(["the", "cat", "sat", "the", "cat"], 2), [0, 3]);
```
`findRepeatedPhrases` should return all start indices for overlapping repeated phrases.
```js
assert.sameDeepOrderedMembers(findRepeatedPhrases(["ba", "ba", "ba"], 2), [0, 1]);
```
`analyzeTexts` should be a function.
```js