implementing data structures algorithms in javascript