Blog2013 ≫ Can you javascript under pressure?

This tested our brains 1 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)

  1. Removed old toys.usvsth3m.com/javascript-under-pressure/ link here.

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

⬅️ :: ➡️

Paulʼs weblog - I live in A sleepy town, Kent. Wed and dad to 2, I'm 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, family tree stuff, TV, squirrels, pirates ☠️, lego, and time travel.