Reverse word with char in place

Run Settings
LanguageJavaScript
Language Version
Run Command
function reverseSenWithSpecialChar(str){ let specialSet= new Set([";","\'","\:","\"","\\","\|","\.","\<","\>","\?","\!","\,"]); let revString = new Array(str.length).fill(null); for(let x=0; x<str.length; x++){ if(specialSet.has(str[x])){ revString[x]=str[x] } } let word='',reverseSen='' for(let x=str.length-1; x>-1; x--){ // console.log(str[x]) if(str[x]===" "){ reverseSen=word+" "+reverseSen; word='' } else{ if(!specialSet.has(str[x])) word+=str[x]; } } reverseSen= word+" "+reverseSen; let i=0,j=0; while(i<revString.length){ if(!revString[i]){ revString[i]=reverseSen[j]; j++; } i++; } return revString.join(''); } console.log(reverseSenWithSpecialChar("I'm a cat, yo'u?"));
Editor Settings
Theme
Key bindings
Full width
Lines