Learn by Doing Lodash

thecodeduck
2 min readNov 1, 2018

I’m a self-taught programmer. Even though I’ve been coding JavaScript off and on for years, it’s not my day job. I’d like it to be, but I’ve always felt that my core understanding of programming had some… holes.

So in addition to reading all the books, taking all the online courses, and drinking all the coffee, someone suggested I’d take a crack at recreating lodash. The idea is that my attempting to solve each ‘problem’ (method) of this utility library will foster a deeper understanding of data manipulation in JS and functional programming. And, you know, for fun.

Setting up

Originally, I wanted to scrape the lodash documentation page and then use BeautifulSoup to hack it up into nice little bites that python could use to automatically create a folder structure. Something like this:

methodName
— methodName.js
— methodName.tests.js
— methodName_description.md

And just like that, all 315 methods would be outlined and ready for me to attack. Grabbing all the method names was straightforward: each was wrapped in a <h3> tag, and included its own name as the id (for anchor links). Boom, done.

For the description markdown file, I’d ideally include both the arguments and description of the method. This meant navigating the tree a bit. Normally that’s a non-issue, but 20 minutes later I couldn’t pull the one <p> tag I wanted and instead kept ending up with all its siblings. No matter how many different ways I tried getting at it, the description came along with everything I didn’t want. It took another 20 minutes for me to check the actual page source, rather than just looking at the page’s HTML with the Chrome inspector.

The lodash documentation source — without any closing </p> tags.

Not a single </p>. Not one.

I felt a little better that it wasn’t me messing up, but it still killed my dreams of setting up the repo with a simple terminal command. Instead, I’ll be just be sitting here, manually creating all 315 folders for each method by hand…

--

--