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 your 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 5-minute thinking, I started writing JavaScript. 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 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 head was full of block 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. But by the time I finished running, I've got a slight idea of how my function should 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