Consider the following simple array:
var foods = [\'hotdog\', \'hamburger\', \'soup\', \'sandwich\', \'hotdog\', \'watermelon\', \'hotdog\'];
var foods = ['hotdog', 'hamburger', 'soup', 'sandwich', 'hotdog', 'watermelon', 'hotdog'];
var result = _.chain(foods).countBy().pairs().max(_.last).head().value();
console.log(result);
countBy: Sorts a list into groups and returns a count for the number of objects in each group.
pairs: Convert an object into a list of
[key, value]pairs.max: Returns the maximum value in list. If an iterator function is provided, it will be used on each value to generate the criterion by which the value is ranked.
last: Returns the last element of an array
head: Returns the first element of an array
chain: Returns a wrapped object. Calling methods on this object will continue to return wrapped objects until value is used.
value: Extracts the value of a wrapped object.