JavascriptJavaScript, 60 Bytes
I know there is already a JS answer here, but wanted to do it without regexes, because regex is really almost a language by itself. I'm sorry if you feel I shouldn't post this, this is my first post.X
is the string to be operated upon. I know there is already a JS answer here, but wanted to do it without regexes, because regex is really almost a language by itself. I'm sorry if you feel I shouldn't post this, this is my first post.X
is the string to be operated upon.
while((z=x.indexOf('^D'))>0){x=x.slice(0,z-1)+x.slice(z+2);}
while((z=x.indexOf('^D'))>0){x=x.slice(0,z-1)+x.slice(z+2);}
Test
Put this into your browser's address bar.Put this into your browser's address bar.
javascript:x=prompt('Enter the sentence to be erased');while((z=x.indexOf('^D'))>0){x=x.slice(0,z-1)+x.slice(z+2);}alert(x);
javascript:x=prompt('Enter the sentence to be erased');while((z=x.indexOf('^D'))>0){x=x.slice(0,z-1)+x.slice(z+2);}alert(x);
I love JS because it will let you do things like saying
(z=x.indexOf('^D))>0
, and it will both assign z.indexOf('^D');
to x
and evaluate z.indexOf('^D')
in the condition, which saves me precious bytes in this problem. It's not very usefull otherwise, but it's fun! I love JS because it will let you do things like saying (z=x.indexOf('^D))>0
, and it will both assign z.indexOf('^D');
to x
and evaluate z.indexOf('^D')
in the condition, which saves me precious bytes in this problem. It's not very useful otherwise, but it's fun!