Skip to content

This is how we flatten data: flatten.js

Daisho Komiyama edited this page Aug 29, 2019 · 36 revisions

One day somewhere in Canada, imagine you got a visualization task with humongous size of dataset out of nowhere, you probably have to sit tight, wish yourself best luck then try very hard to wrap your head around it. I know it because I did it.

Speaking of my case it was disaster at least at the beginning. I've spent some time just looking at screen, counting how many properties there were within an array of objects with a few hundreds of them. After brief thinking time, I started writing JavaScript based on a shallow plan. This is a bad start.

After a few hours, I ended up having a few functions. Not like the principal I always had in my mind; don't repeat yourself, what each function does was way too specific that makes almost impossible for the functions to be reused in other use-cases. They are so-called one-time-use-only functions. I hated them, even hated myself and circumstances that forced me to produce those trash.

I walked out the office, thinking to go for a jog that night.

My mind was full of programming even during a run. I traced each value from beginning to end in a function I built in my head. I did it so many times simply due to difficulty; number of data layers are beyond imagination. Though, by the time I finished running, I've got a slight idea of how my functions were supposed to be built. This result indicates I have to rewrite everything. but I was totally excited.

When I woke up, I came up with an new idea

Clone this wiki locally