JavaScript reduce

Tonight Matt posted a JavaScript solution to a problem he saw described elsewhere. Here’s a version that I whipped up to use JavaScript 1.8’s new Array.prototype.reduce function.

var arrVal = ["a", "b", "c", "c", "d", "e", "e", "e", "e", "e",
  "f", "e", "f", "e", "f", "a", "a", "a", "f", "f", "f"];

function group(previousValue, currentValue, index, arr)
{
	if (index > 0  && arr[index - 1] == currentValue)
		return previousValue.slice(0,-1).concat([previousValue.slice(-1)[0].concat(currentValue)]);
	return previousValue.concat([[currentValue]]);
}

function format(previousValue, currentValue, index, arr)
{
	return previousValue.concat(
		currentValue.length < 3 ? 
		currentValue.join(" ") :
		currentValue.slice(0,2).join(" ") + 
			" " + currentValue.slice(2).join(" ") + "");
}

print(arrVal.reduce(group, []).reduce(format, []).join(" "));

Dear mister robber

Dear mister (or ms though I doubt it) robber,

Thank you for smashing my car window last week while it was parked in my parking space. The lousy handful of change that you stole, that probably amounted to a maximum of $15, is now going to cost me $463 in repairs (along with a couple of hours of cleaning up and delaying a trip I wanted to take). I hope that it was really worth it for you and that you did really need the money — next time I might just leave my doors unlocked to save us both the hassle.

Cheers,
Your victim,
Chris

FedEx Day 8 summarised

Fellow Atlassian Mark Chaimungkalanont has just posted a summary on the mammoth undertaking that was Atlassian’s eighth FedEx day. (We deliver!) A huge congratulations to all participants; it’s always a very exciting time to be at the office when every single engineer at Atlassian is furiously banging out fresh code and fresh ideas.

This was a somewhat emotional FedEx day for me, being almost precisely a year from FedEx Day 6, when things took an unexpectedly bad turn for me and began what was without a doubt the most challenging, and changing six months of my life. I made it all the way to the end this time and I feel so much better than I ever, ever thought I would during those scarily dark days.

I’m also fairly proud of my monstrous creation as well. 🙂

The online advertising stupidity continues

Here’s an email I just sent to the Sydney Morning Herald online:

Hi,

Just wanted to let you know that the insidious, annoying, inline pop over ads that feature on the front page of smh.com.au have now driven me from using your site any more. I’d much rather use news.com.au and abc.net.au/news rather than putting up with the frustration and distraction of your needlessly obstrusive advertisements.

When will the online media learn that frustrating users does not engender their goodwill toward you or your sponsors and in fact has quite the opposite effect?

Sincerely,
Chris

I just don’t understand the tactic. If this type of thing was possible with printed newspapers would they do it and would their readership put up with it?