@@ -109,6 +109,12 @@ <h1>Writing Style Analyzer</h1>
109109 'understood' , 'worn' , 'won' , 'written'
110110] ;
111111
112+ // Helper function to strip punctuation from words
113+ function stripPunctuation ( word ) {
114+ // Remove all punctuation from the word, preserving internal hyphens
115+ return word . replace ( / ^ [ ^ \w \s - ] + | [ ^ \w \s - ] + $ / g, '' ) ;
116+ }
117+
112118// Helper function to get word positions with their original text
113119function getWordPositions ( text ) {
114120 const words = [ ] ;
@@ -151,7 +157,8 @@ <h1>Writing Style Analyzer</h1>
151157 const wordPositions = getWordPositions ( text ) ;
152158
153159 wordPositions . forEach ( pos => {
154- if ( weaselWords . includes ( pos . word . toLowerCase ( ) ) ) {
160+ const strippedWord = stripPunctuation ( pos . word . toLowerCase ( ) ) ;
161+ if ( weaselWords . includes ( strippedWord ) ) {
155162 results . push ( {
156163 word : pos . word ,
157164 context : getContext ( text , pos )
@@ -168,13 +175,13 @@ <h1>Writing Style Analyzer</h1>
168175 const wordPositions = getWordPositions ( text ) ;
169176
170177 for ( let i = 0 ; i < wordPositions . length - 1 ; i ++ ) {
171- const currentWord = wordPositions [ i ] . word . toLowerCase ( ) ;
172- const nextWord = wordPositions [ i + 1 ] . word . toLowerCase ( ) ;
178+ const currentWord = stripPunctuation ( wordPositions [ i ] . word . toLowerCase ( ) ) ;
179+ const nextWord = stripPunctuation ( wordPositions [ i + 1 ] . word . toLowerCase ( ) ) ;
173180
174181 if ( beVerbs . includes ( currentWord ) ) {
175182 if ( nextWord . endsWith ( 'ed' ) || irregularVerbs . includes ( nextWord ) ) {
176183 results . push ( {
177- construction : `${ currentWord } ${ nextWord } ` ,
184+ construction : `${ wordPositions [ i ] . word } ${ wordPositions [ i + 1 ] . word } ` ,
178185 context : getContext ( text , wordPositions [ i ] )
179186 } ) ;
180187 }
@@ -189,7 +196,10 @@ <h1>Writing Style Analyzer</h1>
189196 const wordPositions = getWordPositions ( text ) ;
190197
191198 for ( let i = 1 ; i < wordPositions . length ; i ++ ) {
192- if ( wordPositions [ i ] . word . toLowerCase ( ) === wordPositions [ i - 1 ] . word . toLowerCase ( ) ) {
199+ const currentWordStripped = stripPunctuation ( wordPositions [ i ] . word . toLowerCase ( ) ) ;
200+ const prevWordStripped = stripPunctuation ( wordPositions [ i - 1 ] . word . toLowerCase ( ) ) ;
201+
202+ if ( currentWordStripped === prevWordStripped && currentWordStripped . length > 0 ) {
193203 results . push ( {
194204 word : wordPositions [ i ] . word ,
195205 context : getContext ( text , wordPositions [ i ] )
0 commit comments