Range sequence in JavaScript

Now that I've been exploring the functional programming style in ES6, one of the things I've found missing from the standard library is some sort of range function. You see it a lot in functional languages like Clojure or scripting languages like Python where there isn't a classic C-style loop (int i; i < len; i++). It's commonly used when you explicitly want to access an index in an array but it can also be used in combination with other functions.

let range = (start, end) => {  
  let size = end ? end - start : start;
  start = end ? start : 0;
  return Array.from(Array(size)).map((_, i) => start + i);
};

A novel example is getting the sum of the first 100 numbers.

range(100).reduce((i, sum) => sum + i)  
// -> 4950

Bret Lowrey

Code is like a war - the best code is one never written.

Florida, USA