OK, Dustin Diaz (via Paul O’Shannessy) managed to delay my lunch by 30 secs.
var arr = ['a', 'b', 'c', 'c', 'd','e', 'e',
'e', 'e', 'e', 'f', 'e', 'f', 'e',
'f', 'a', 'a', 'a', 'f', 'f', 'f'];
var solution='a b c c d e e <span>e e e</span> f e f e f a a <span>a</span> f f <span>f</span>';
var won = arr.join(' ').replace(/((\w)\s\2\s)((?:\2\s?)+)(?=\s|$)/g, '$1<span>$3</span>') == solution;
Thanks to the wonderful interactive environment of Firefox’s “Error Console” (formerly known as JavaScript Console), my pasta didn’t get too cold :)



July 10th, 2008 at 4:46 pm
How did you use the Error console? That would be a useful trick to learn. I tired pasting your code into it and clicking on Evaluate but it didn’t do anything.
July 10th, 2008 at 7:12 pm
@Sam Hasler:
You need to enter all in one line (unless you store variables in a window object, e.g. using “top.arr”) and end the script with an expression but not an assignment, e.g.:
(in one line) will give “true” as its output.
A portable, concise bookmarklet to quickly test multiline JS is the following:
javascript:document.body.innerHTML="<textarea onchange='eval(this.value)' cols=80 rows=6/>";void(0)July 11th, 2008 at 12:51 am
I like it. Clever use of regular expressions.
July 11th, 2008 at 12:59 am
Thanks
July 12th, 2008 at 6:12 am
pls apologize my stupidity.. but what will this expression do?
July 15th, 2008 at 6:28 am
For whatever reason, I am not able to get your bookmarklet to work?
No matter how I’ve tried it, I end up with an empty box at the top of the screen?
If I copy/paste into the URL line (prefaced by javascript: ), I correctly get "true".
I had this bookmarklet (which I picked up somewhere?) that I called ‘Execute HTML’. If I recall, I would use it from time to time to execute HTML snippets. But when I try it on on the script, again I end up with a blank page & no "true".
javascript:(function(){var sel;function getText(w){if(w.getSelection){return w.getSelection();}if(w.document.getSelection){return w.document.getSelection();}return w.document.selection.createRange().text;}function getSel(w){try{sel=getText(w);if(sel)return;for(var i=0;F=w.frames[i];i++){getSel(F);if(sel)return;}}catch(e){}}getSel(window);if(!sel)alert('Select some text.');else{w=open();w.document.write(sel);w.document.close();}})()
Nothing here either, http://www.javascriptwindow.com/ ?
July 15th, 2008 at 11:59 am
@therube:
My script has no output per se.
If you want it to show a result, add this line:
alert(won);
August 6th, 2008 at 12:41 am
cool,
i am not a programmer,
so i dont know what is this,
but,
what i see about you is
you are such a great guy
u own an IT company,
u wrote great stuff
and the most is,
u are italian!
;)
bytheway,
i love pizza