Blog2013 ≫ Can you javascript under pressure?

This tested our brains1 at work today. Here is my solution to the last one:

function arraySum( i ) {
  return i.reduce( function ( a, b ) {
    if ( b instanceof Array ) b = arraySum( b );
    if ( typeof b !== 'number' ) return a;
    return a + b;
  }, 0 );
}

I was dead slow as I kept insisting on using reduce, and forgetting what the params are for it, but I got there in 16 mins.

(and I took a phone call in the middle of that)

javascript: Programming language of the web, mostly how I make my living.

⬅️ :: ➡️

Paul Clarke's weblog - I live in Hythe near Folkestone. Wed to Clare + dad to 2, I am a full-stack web engineer, and I do javascript / nodejs, some ruby, python, php ect ect. I like pubbing, parkrun, eating, home-automation and other diy jiggery-pokery, history, genealogy, Television, squirrels, pirates, lego, and time travel.