Some Lodash functions in ES6

There’s quite a few posts out there with Lodash functions but there’s a few that I couldn’t find so here’s a list of those ones. Check back often because I will very likely keep updating this page with more and more as I go along.

times


// lodash
_.times(n, iteratee);

// ES6
Array.from({ length: n }, iteratee);

groupBy

// lodash
_.groupBy(array, fn);

// ES6
const groupBy = (arr, fn) => {
  return arr.reduce((acc, val) => {
    (acc[fn(val)] = acc[fn(val)] || []).push(val);
    return acc;
  }, {});
}

head and tail


// lodash
const tail = _.tail(array);

// ES6
const { head, ...tail } = array;