Lodash in the real world: Sample
A powerful and reliable ally to many recent projects of mine has been the super hero Lodash. It’s ability to deal with many forms of data in an intelligent and intuitive way can change an otherwise ugly problem into a beautifully simple solution.
Scenario
Our designer pitched a filter-as-you-type search bar for our sidebar. It’s placeholder is intended to show some potential valid search terms.
Of course we could write in some static examples, but what a great way to recommend new content each time a user uses the site by randomly selecting some available items as search examples!
Solution
Lodash makes this quite easy with _.sample(). Quite simply, when given an array (or collection) and a number of results expected, you’ll receive a shortened sampled array of that many results.
So there you go, a real life scenario where Lodash has made at least my day a little easier. Perhaps it can for you as well.