nodejs port of python's defaultdict