Skip to content

Commit 59c2e27

Browse files
Create script.js
1 parent 6a8fea3 commit 59c2e27

File tree

1 file changed

+16
-0
lines changed
  • Specialized Areas/Regular Expressions/Consecutive duplicate words

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Consecutive Duplicate Words Detector
2+
// This regex finds repeated words that appear consecutively, such as "the the" or "and and".
3+
// Useful for grammar or text quality checks.
4+
5+
const duplicateWordsRegex = /\b([A-Za-z]+)\s+\1\b/gi;
6+
7+
function hasDuplicateWords(text) {
8+
return duplicateWordsRegex.test(text);
9+
}
10+
11+
// Example usage:
12+
console.log(hasDuplicateWords("This is the the example.")); // true
13+
console.log(hasDuplicateWords("We need to to check this.")); // true
14+
console.log(hasDuplicateWords("Everything looks good here.")); // false
15+
console.log(hasDuplicateWords("Hello hello world.")); // true (case-insensitive)
16+
console.log(hasDuplicateWords("No repetition found.")); // false

0 commit comments

Comments
 (0)