Implementing some common algorithm and data structures in js