Monthly Archives: March 2012

Array equality in JavaScript – functional style

So it turns out there is no built-in test for array equality in JavaScript. There are some suggestions here on StackOverflow, but I wanted to see if there was a simple answer using Functional Javascript.

Here’s my attempt:

ArrayEq: function(a1,a2) {
    return reduce("x && y",true,map("x[0]==x[1]",zip(a1,a2)));
}

Reading from right to left, the zip transforms them into an array of pairs, then each pair is compared, and then the reduce applies the && operator to each boolean result in turn.

Posted in Uncategorized | 1 Comment

Quick random passwords

I’m sure there are lots of password generators out there, but a quick way of achieving this at the command line is something like


cat /dev/urandom | dd count=1 2> /dev/null | base64

Then copy and paste as much as you need. The result will be fairly unmemorable, but apart from OS login passwords which need to be typed, most logins can be automated, eg by using user:pass@host style URLs.

Posted in Uncategorized | Leave a comment