in javascript you don't have to write:
if (typeof _.first(bucket) == 'undefined')
you just could write:
if (_.first(bucket))
but this will catch also null values and other falsy values, it can be good thing, it depends.
If want only check for undefinied you can write:
if (_.first(bucket) === undefined)