Share
Embed
Transcript
180 slides
-
Underscore.js Overview of functions Part I: Collections and Arrays Marcin
Tabaka June 30, 2015 -
Outline Part I: • Introduction • Collections • Arrays Part
II: • Functions • Objects • Utilities • Summary -
What is Underscore.js? • A JavaScript library which provides utility
functions for common programming tasks • Made by Jeremy Ashkenas (also known for Backbone.js and CoffeeScript) • Similar to features provided by Prototype.js and the Ruby language • Opts for a functional programming design instead of extending object prototypes -
What is Underscore.js? • Provides over 100 functions • Common
workaday functional helpers – e.g. map, filter, invoke • But also more specialized goodies: function binding, javascript templating, creating quick indexes, deep equality testing, and so on. -
What is Underscore.js? • The documentation refers to Underscore.js as
"the tie to go along with jQuery's tux, and Backbone.js's suspenders" • Currently Underscore.js is one of the most depended upon packages in the Node.js JavaScript runtime -
Dependencies • Underscore.js requires no dependencies and in fact it
falls back to the native implementations when available • If the environment supports ECMA Script 5, implementations for forEach, map, reduce, keys, bind and even more, those implementations are used in favor of what's implemented in Underscore.js itself -
Getting Started • All you need to do it's add
it to your project – download the source code, include it in your page and you're good to go • Can be installed via popular package managers like: Node.js, Meteor.js, Require.js, Bower or Component -
Getting Started • Underscore creates and exposes all its functionality
via a single global scope object • This object is the titular underscore: _ • Similar to how jQuery works with the dollar ($) symbol • Like with jQuery, you can remap the object to avoid conflicts: _.noConflict() -
Functional or Object-Oriented? You can use Underscore in either an
object- oriented or a functional style, depending on your preference. var object = { "key1": "value1", "key2": "value2" }; -
Functional or Object-Oriented? You can use Underscore in either an
object- oriented or a functional style, depending on your preference. var object = { "key1": "value1", "key2": "value2", }; _(object).keys(); // => ["key1", "key2"] -
Functional or Object-Oriented? You can use Underscore in either an
object- oriented or a functional style, depending on your preference. var object = { "key1": "value1", "key2": "value2", }; _(object).keys(); // => ["key1", "key2"] _.keys(object); // => ["key1", "key2"] -
Collection Functions (Arrays or Objects) • Collection functions work on
arrays, objects, and array-like objects (such as arguments and NodeList) • They use duck-typing, so passing objects with a numeric length property should be avoided -
Collection Functions (Arrays or Objects) contains invoke sample countBy map
shuffle each max size every min some filter partition sortBy find pluck toArray findWhere reduce where groupBy reduceRight indexBy reject -
each (alias: forEach) Underscore.js docs: Iterates over a list of
elements, yielding each in turn to an iteratee function -
each (alias: forEach) var obj = { "key1": "value1", ...
}; $.each(obj, function(key, value) { key + ": " + value; }); // => key1: value1... Underscore.js: jQuery: _.each(obj, function(value, key) { key + ": " + value; }); // => key1: value1... -
each (alias: forEach) var arr = ["value1", "value2", "value3"]; $.each(arr,
function(index, value) { index + ": " + value; }); // => 0: value1... Underscore.js: jQuery: _.each(arr, function(value, index) { index + ": " + value; }); // => 0: value1... -
each (alias: forEach) var arr = ["value1", "value2", "value3"]; $.each(arr,
function(index, value) { this; }); // => ? Underscore.js: jQuery: _.each(arr, function(value, index) { this; }); // => ? -
each (alias: forEach) var arr = ["value1", "value2", "value3"]; $.each(arr,
function(index, value) { this; }); // => "value1" Underscore.js: jQuery: _.each(arr, function(value, index) { this; }); // => Window -
each (alias: forEach) arr = ["val1","val2","val3",“val4”,“val5”]; $.each(arr, function(index, value) {
if (value === "val2") return; if (value === "val4") return false; alert(value); }); jQuery: -
each (alias: forEach) arr = ["val1","val2","val3",“val4”,“val5”]; $.each(arr, function(index, value) {
if (value === "val2") return; if (value === "val4") return false; alert(value); }); // => alerts "val1" and "val3" jQuery: -
each (alias: forEach) arr = ["val1","val2","val3",“val4”,“val5”]; $.each(arr, function(index, value) {
if (value === "val2") return; // => "continue" if (value === "val4") return false; alert(value); }); // => alerts "val1" and "val3" jQuery: -
each (alias: forEach) arr = ["val1","val2","val3",“val4”,“val5”]; $.each(arr, function(index, value) {
if (value === "val2") return; // => "continue" if (value === "val4") return false; // => "break" alert(value); }); // => alerts "val1" and "val3" jQuery: -
each (alias: forEach) arr = ["val1","val2","val3",“val4”,“val5”]; _.each(arr, function(value, index) {
if (value === "val2") return; if (value === "val4") return false; alert(value); }); Underscore.js: -
each (alias: forEach) arr = ["val1","val2","val3",“val4”,“val5”]; _.each(arr, function(value, index) {
if (value === "val2") return; if (value === "val4") return false; alert(value); }); // => alerts "val1", "val3", "val5" Underscore.js: -
each (alias: forEach) arr = ["val1","val2","val3",“val4”,“val5”]; _.each(arr, function(value, index) {
if (value === "val2") return; // => "continue" if (value === "val4") return false; alert(value); }); // => alerts "val1", "val3", "val5" Underscore.js: -
each (alias: forEach) arr = ["val1","val2","val3",“val4”,“val5”]; _.each(arr, function(value, index) {
if (value === "val2") return; // => "continue" if (value === "val4") return false; // => "continue" alert(value); }); // => alerts "val1", "val3", "val5" Underscore.js: -
each (alias: forEach) arr = ["val1","val2","val3",“val4”,“val5”]; _.each(arr, function(value, index) {
if (value === "val2") return; // => "continue" if (value === "val4") return false; // => "continue" alert(value); }); // Can't break out of a _.each loop Underscore.js: -
each (alias: forEach) var arr = ["key1","key2","key3"]; var obj =
{"key1": "val1", ... }; _.each(arr, function(value, index, list) { value; index; list; this; this[value]; }, obj); -
each (alias: forEach) var arr = ["key1","key2","key3"]; var obj =
{"key1": "val1", ... }; _.each(arr, function(value, index, list) { value; // => "key1" index; list; this; this[value]; }, obj); -
each (alias: forEach) var arr = ["key1","key2","key3"]; var obj =
{"key1": "val1", ... }; _.each(arr, function(value, index, list) { value; // => "key1" index; // => 0 list; this; this[value]; }, obj); -
each (alias: forEach) var arr = ["key1","key2","key3"]; var obj =
{"key1": "val1", ... }; _.each(arr, function(value, index, list) { value; // => "key1" index; // => 0 list; // => arr this; this[value]; }, obj); -
each (alias: forEach) var arr = ["key1","key2","key3"]; var obj =
{"key1": "val1", ... }; _.each(arr, function(value, index, list) { value; // => "key1" index; // => 0 list; // => arr this; // => obj this[value]; }, obj); -
each (alias: forEach) var arr = ["key1","key2","key3"]; var obj =
{"key1": "val1", ... }; _.each(arr, function(value, index, list) { value; // => "key1" index; // => 0 list; // => arr this; // => obj this[value]; // => "value1" }, obj); -
map (alias: collect) Underscore.js docs: Produces a new array of
values by mapping each value in list through a transformation function (iteratee). -
map (alias: collect) results = _.map([1, 2, 3], function (num)
{ return num * 3; }); results = _.map({one: 1, two: 2, three: 3}, function (num, key) { return num * 3; } ); -
map (alias: collect) results = _.map([1, 2, 3], function (num)
{ return num * 3; }); // => [3, 6, 9] results = _.map({one: 1, two: 2, three: 3}, function (num, key) { return num * 3; } ); -
map (alias: collect) results = _.map([1, 2, 3], function (num)
{ return num * 3; }); // => [3, 6, 9] results = _.map({one: 1, two: 2, three: 3}, function (num, key) { return num * 3; } ); // => [3, 6, 9] -
map (alias: collect) var params = { name: 'alice', loc:
'US', category: 'clothing' }; _.map(params, function (value, key) { return key + '=' + value; }).join('&'); -
map (alias: collect) var params = { name: 'alice', loc:
'US', category: 'clothing' }; _.map(params, function (value, key) { return key + '=' + value; }).join('&'); // => name=alice&loc=US&category=clothing -
reduce (aliases: inject, foldl) Underscore.js docs: Boils down a list
of values into a single value. Memo is the initial state of the reduction, and each successive step of it should be returned by iteratee. The iteratee is passed four arguments: the memo, then the value and index (or key) of the iteration, and finally a reference to the entire list. Right-associative version: reduceRight (foldr) -
reduce (aliases: inject, foldl) sum = _.reduce([1, 2, 3], function
(memo, num) { return memo + num; }, 0); petsCount = _.reduce( pets, function (memo, pet) { if (pet.species === 'cat') memo.cats++; if (pet.species === 'dog') memo.dogs++; return memo; }, { cats: 0, dogs: 0 } ); -
reduce (aliases: inject, foldl) sum = _.reduce([1, 2, 3], function
(memo, num) { return memo + num; }, 0); // => 6 petsCount = _.reduce( pets, function (memo, pet) { if (pet.species === 'cat') memo.cats++; if (pet.species === 'dog') memo.dogs++; return memo; }, { cats: 0, dogs: 0 } ); -
reduce (aliases: inject, foldl) sum = _.reduce([1, 2, 3], function
(memo, num) { return memo + num; }, 0); // => 6 petsCount = _.reduce( pets, function (memo, pet) { if (pet.species === 'cat') memo.cats++; if (pet.species === 'dog') memo.dogs++; return memo; }, { cats: 0, dogs: 0 } ); // => { cats: 7, dogs: 5 } -
find (alias: detect) Underscore.js docs: Looks through each value in
the list, returning the first one that passes a truth test (predicate), or undefined if no value passes the test. The function returns as soon as it finds an acceptable element, and doesn't traverse the entire list. -
find (alias: detect) even = _.find([1, 2, 3, 4], function
(num) { return num % 2 == 0; }); var primaryAccount = _.find( accounts, function (account) { return account.type === "primary"; } ); -
find (alias: detect) even = _.find([1, 2, 3, 4], function
(num) { return num % 2 == 0; }); // => 2 var primaryAccount = _.find( accounts, function (account) { return account.type === "primary"; } ); -
find (alias: detect) even = _.find([1, 2, 3, 4], function
(num) { return num % 2 == 0; }); // => 2 var primaryAccount = _.find( accounts, function (account) { return account.type === "primary"; } ); // => { number: "...", type: "primary" } -
filter (alias: select) Underscore.js docs: Looks through each value in
the list, returning an array of all the values that pass a truth test (predicate). -
filter (alias: select) var even = _.filter( [1, 2, 3,
4, 5, 6], function (num) { return num % 2 == 0; } ); -
filter (alias: select) var even = _.filter( [1, 2, 3,
4, 5, 6], function (num) { return num % 2 == 0; } ); // => [2, 4, 6] -
filter (alias: select) var filtered = _.filter(json, function (item) {
return (item.status === "active" && item.priority === "high"); }); -
where Underscore.js docs: Looks through each value in the list,
returning an array of all the values that contain all of the key-value pairs listed in properties. -
findWhere Underscore.js docs: Looks through the list and returns the
first value that matches all of the key-value pairs listed in properties. If no match is found, or if list is empty, undefined will be returned. -
findWhere // First high priority item in JSON data _.findWhere(json,
{ priority: "high" }); -
reject Underscore.js docs: Returns the values in list without the
elements that the truth test (predicate) passes. The opposite of filter. -
reject var odd = _.reject( [1, 2, 3, 4, 5,
6], function(num) { return num % 2 == 0; } ); -
reject var odd = _.reject( [1, 2, 3, 4, 5,
6], function(num) { return num % 2 == 0; } ); // => [1, 3, 5] -
reject var availableDomains = ["test.com", "test.net", "test.org"]; _.reject( availableDomains, function
(element) { return element === "test.net"; } ); -
reject var availableDomains = ["test.com", "test.net", "test.org"]; _.reject( availableDomains, function
(element) { return element === "test.net"; } ); // => ["test.com", "test.org"] -
every (alias: all) Underscore.js docs: Returns true if all of
the values in the list pass the predicate truth test. -
every (alias: all) _.every( [true, 1, null, 'yes'], function(value) {
return value; } ); -
every (alias: all) _.every( [true, 1, null, 'yes'], function(value) {
return value; } ); // => false -
every (alias: all) _.every( [true, 1, null, 'yes'], function(value) {
return value; } ); // => false _.every([true, 1, null, 'yes'], _.identity); -
every (alias: all) _.every( [true, 1, null, 'yes'], function(value) {
return value; } ); // => false _.every([true, 1, null, 'yes'], _.identity); // => false -
every (alias: all) // Save data if all forms are
valid if (_.every( view.$(".form"), function (form) { return $(form).valid(); })) { something.save(); } -
some (alias: any) Underscore.js docs: Returns true if any of
the values in the list pass the predicate truth test. Short-circuits and stops traversing the list if a true element is found. -
some (alias: any) items = [ { id: 124, status:
"completed" }, { id: 125, status: "failed" } ]; _.some(items, function (item) { return _.contains( ["failed", "canceled"], item.status ); } ); -
some (alias: any) items = [ { id: 124, status:
"completed" }, { id: 125, status: "failed" } ]; _.some(items, function (item) { return _.contains( ["failed", "canceled"], item.status ); } ); // => true -
contains (alias: includes) Underscore.js docs: Returns true if the value
is present in the list. Uses indexOf internally, if list is an Array. Use fromIndex to start your search at a given index. -
invoke Underscore.js docs: Calls the method named by methodName on
each value in the list. Any extra arguments passed to invoke will be forwarded on to the method invocation. -
invoke _.invoke( [ [5, 1, 7], [3, 2, 1] ],
'sort' ); // => [ [1, 5, 7], [1, 2, 3] ] -
pluck Underscore.js docs: A convenient version of what is perhaps
the most common use-case for map: extracting a list of property values. -
pluck var items = [ { id: 123, symbol: "foo"
}, { id: 456, symbol: "bar" }, { id: 789, symbol: "baz" } ]; var symbols = _.pluck(items, "symbol"); -
pluck var items = [ { id: 123, symbol: "foo"
}, { id: 456, symbol: "bar" }, { id: 789, symbol: "baz" } ]; var symbols = _.pluck(items, "symbol"); // => ["foo", "bar", "baz"] -
max / min Underscore.js docs: Returns the maximum/minimum value in
list. If an iteratee function is provided, it will be used on each value to generate the criterion by which the value is ranked. -Infinity (+Infinity for mix) is returned if list is empty, so an isEmpty guard may be required. -
max / min var items = [ { id: 123,
priority: 0 }, { id: 456, priority: 9 }, { id: 789, priority: 3 } ]; _.max(items, function (item) { return item.priority; }); -
max / min var items = [ { id: 123,
priority: 0 }, { id: 456, priority: 9 }, { id: 789, priority: 3 } ]; _.max(items, function (item) { return item.priority; }); // => { id: 456, priority: 9 } -
sortBy Underscore.js docs: Returns a (stably) sorted copy of list,
ranked in ascending order by the results of running each value through iteratee. iteratee may also be the string name of the property to sort by (eg. length). -
sortBy _.sortBy( ["alice", "bob", "fred"], function (name) { return name.length;
} ); // => ["bob", "fred", "alice"] -
sortBy var items = [ { id: 123, priority: 0
}, { id: 456, priority: 9 }, { id: 789, priority: 3 } ]; _.sortBy(items, 'priority'); -
sortBy var items = [ { id: 123, priority: 0
}, { id: 456, priority: 9 }, { id: 789, priority: 3 } ]; _.sortBy(items, 'priority'); // => [ // { id: 123, priority: 0 }, // { id: 789, priority: 3 }, // { id: 456, priority: 9 } // ] -
groupBy Underscore.js docs: Splits a collection into sets, grouped by
the result of running each value through iteratee. If iteratee is a string instead of a function, groups by the property named by iteratee on each of the values. -
groupBy _.groupBy([1.3, 2.1, 2.4], function (num) { return Math.floor(num); });
// => { 1: [1.3], 2: [2.1, 2.4] } -
groupBy _.groupBy([1.3, 2.1, 2.4], function (num) { return Math.floor(num); });
// => { 1: [1.3], 2: [2.1, 2.4] } _.groupBy( ['alice', 'bob', 'carol'], 'length' ); -
groupBy _.groupBy([1.3, 2.1, 2.4], function (num) { return Math.floor(num); });
// => { 1: [1.3], 2: [2.1, 2.4] } _.groupBy( ['alice', 'bob', 'carol'], 'length' ); // => { 3: ["bob"], 5: ["alice", "carol"] } -
indexBy Underscore.js docs: Given a list, and an iteratee function
that returns a key for each element in the list (or a property name), returns an object with an index of each item. Just like groupBy, but for when you know your keys are unique. -
indexBy var items = [ { id: 123, priority: 0
}, { id: 456, priority: 9 }, { id: 789, priority: 3 } ]; _.indexBy(items, 'id'); -
indexBy var items = [ { id: 123, priority: 0
}, { id: 456, priority: 9 }, { id: 789, priority: 3 } ]; _.indexBy(items, 'id'); // => [ // "123": { id: 123, priority: 0 }, // "456": { id: 456, priority: 9 }, // "789": { id: 789, priority: 3 } // ] -
countBy Underscore.js docs: Sorts a list into groups and returns
a count for the number of objects in each group. Similar to groupBy, but instead of returning a list of values, returns a count for the number of values in that group. -
countBy _.countBy([1, 2, 3, 4, 5], function (num) { return
num % 2 == 0 ? 'even': 'odd'; }); -
countBy _.countBy([1, 2, 3, 4, 5], function (num) { return
num % 2 == 0 ? 'even': 'odd'; }); // => { odd: 3, even: 2 } -
sample Underscore.js docs: Produce a random sample from the list.
Pass a number to return n random elements from the list. Otherwise a single random item will be returned. -
sample _.sample([1, 2, 3, 4, 5, 6]); // => 4
_.sample([1, 2, 3, 4, 5, 6], 3); // => [1, 6, 2] -
toArray Underscore.js docs: Creates a real Array from the list
(anything that can be iterated over). Useful for transmuting the arguments object. -
partition Underscore.js docs: Split array into two arrays: one whose
elements all satisfy predicate and one whose elements all do not satisfy predicate. -
partition _.partition( [0, 1, 2, 3, 4, 5], function (num)
{ return num % 2 == 1; } ); -
partition _.partition( [0, 1, 2, 3, 4, 5], function (num)
{ return num % 2 == 1; } ); // => [ [1, 3, 5], [0, 2, 4] ] -
Array Functions compact initial sortedIndex difference intersection union findIndex last
uniq findLastIndex lastIndexOf unzip first object without flatten range zip indexOf rest -
first (alias: head, take) Underscore.js docs: Returns the first element
of an array. Passing n will return the first n elements of the array. -
initial Underscore.js docs: Returns everything but the last entry of
the array. Especially useful on the arguments object. Pass n to exclude the last n elements from the result. -
last Underscore.js docs: Returns the last element of an array.
Passing n will return the last n elements of the array. -
rest (alias: tail, drop) Underscore.js docs: Returns the rest of
the elements in an array. Pass an index to return the values of the array from that index onward. -
rest (alias: tail, drop) _.rest([2, 4, 6, 8, 10]); //
=> [4, 6, 8, 10] -
compact Underscore.js docs: Returns a copy of the array with
all falsy values removed. In JavaScript, false, null, 0, "", undefined and NaN are all falsy. -
flatten Underscore.js docs: Flattens a nested array (the nesting can
be to any depth). If you pass shallow, the array will only be flattened a single level. -
flatten _.flatten([ 1, [ 2 ], [ 3, [ [
4 ] ] ] ]); -
flatten _.flatten([ 1, [ 2 ], [ 3, [ [
4 ] ] ] ]); // => [ 1, 2, 3, 4 ] -
flatten _.flatten([ 1, [ 2 ], [ 3, [ [
4 ] ] ] ]); // => [ 1, 2, 3, 4 ] _.flatten([ 1, [ 2 ], [ 3, [ [ 4 ] ] ] ], true); -
flatten _.flatten([ 1, [ 2 ], [ 3, [ [
4 ] ] ] ]); // => [ 1, 2, 3, 4 ] _.flatten([ 1, [ 2 ], [ 3, [ [ 4 ] ] ] ], true); // => [ 1, 2, 3, [ [ 4 ] ] ] -
without Underscore.js docs: Returns a copy of the array with
all instances of the values removed. -
without _.without([1, 1, 2, 3, 5, 8, 13], 1, 13);
// => [2, 3, 5, 8] -
union Underscore.js docs: Computes the union of the passed-in arrays:
the list of unique items, in order, that are present in one or more of the arrays. -
union _.union([1, 2, 3], [2, 4, 8], [1, 11, 21]);
// => [1, 2, 3, 4, 8, 11, 21] -
intersection Underscore.js docs: Computes the list of values that are
the intersection of all the arrays. Each value in the result is present in each of the arrays. -
intersection _.intersection( [1, 1, 2, 3, 5], [1, 3, 5],
[5, 1] ); // => [1, 5] -
difference Underscore.js docs: Similar to without, but returns the values
from array that are not present in the other arrays. -
difference _.difference( [1, 2, 3, 4, 5], [2, 4, 6,
8, 10] ); // => [1, 3, 5] -
uniq (alias: unique) Underscore.js docs: Produces a duplicate-free version of
the array, using === to test object equality. In particular only the first occurence of each value is kept. If you know in advance that the array is sorted, passing true for isSorted will run a much faster algorithm. If you want to compute unique items based on a transformation, pass an iteratee function. -
uniq (alias: unique) _.uniq([1, 1, 2, 2, 3, 5]); //
=> [1, 2, 3, 5] -
indexOf Underscore.js docs: Returns the index at which value can
be found in the array, or -1 if value is not present. If you're working with a large array that is already sorted, pass true for isSorted to use a faster binary search ... or, pass a number as the third argument in order to look for the first matching value in the array after the given index. -
lastIndexOf Underscore.js docs: Returns the index of the last occurrence
of value in the array, or -1 if value is not present. Pass fromIndex to start your search at a given index. -
sortedIndex Underscore.js docs: Uses a binary search to determine the
index at which the value should be inserted into the list in order to maintain the list's sorted order. If an iteratee function is provided, it will be used to compute the sort ranking of each value, including the value you pass. The iteratee may also be the string name of the property to sort by (eg. length). -
sortedIndex var events = [ { name: "foo", date: "2015-01-01"
}, { name: "bar", date: "2015-06-30" } ]; _.sortedIndex( events, { name: "baz", date: "2015-04-01" }, 'date' ); -
sortedIndex var events = [ { name: "foo", date: "2015-01-01"
}, { name: "bar", date: "2015-06-30" } ]; _.sortedIndex( events, { name: "baz", date: "2015-04-01" }, 'date' ); // => 1 -
findIndex Underscore.js docs: Similar to _.indexOf, returns the first index
where the predicate truth test passes; otherwise returns -1. -
findIndex _.findIndex( [1.01, 3.14, 3.5], Number.isInteger ); // => -1
(not found) _.findIndex( [1.01, 3.14, 3.5, 4], Number.isInteger ); -
findIndex _.findIndex( [1.01, 3.14, 3.5], Number.isInteger ); // => -1
(not found) _.findIndex( [1.01, 3.14, 3.5, 4], Number.isInteger ); // => 3 -
findLastIndex Underscore.js docs: Like _.findIndex but iterates the array in
reverse, returning the index closest to the end where the predicate truth test passes. -
findLastIndex var items = [ { id: 11, status: 'completed'
}, { id: 21, status: 'in progress' }, { id: 31, status: 'completed' }, { id: 41, status: 'failed' } ]; _.findLastIndex( items, { status: 'completed' } ); -
findLastIndex var items = [ { id: 11, status: 'completed'
}, { id: 21, status: 'in progress' }, { id: 31, status: 'completed' }, { id: 41, status: 'failed' } ]; _.findLastIndex( items, { status: 'completed' } ); // => 2 -
range Underscore.js docs: Creates flexibly-numbered lists of integers, handy for
each and map loops. start defaults to 0; step defaults to 1. Returns a list of integers from start (inclusive) to stop (exclusive), incremented (or decremented) by step, exclusive. Ranges that stop before they start are considered to be zero-length, not negative — for negative ranges, use a negative step. -
range _.range(7); // => [0, 1, 2, 3, 4, 5,
6] _.range(5, 11); -
range _.range(7); // => [0, 1, 2, 3, 4, 5,
6] _.range(5, 11); // => [5, 6, 7, 8, 9, 10] -
range _.range(7); // => [0, 1, 2, 3, 4, 5,
6] _.range(5, 11); // => [5, 6, 7, 8, 9, 10] _.range(0, 100, 20); -
range _.range(7); // => [0, 1, 2, 3, 4, 5,
6] _.range(5, 11); // => [5, 6, 7, 8, 9, 10] _.range(0, 100, 20); // => [0, 20, 40, 60, 80] -
range _.range(7); // => [0, 1, 2, 3, 4, 5,
6] _.range(5, 11); // => [5, 6, 7, 8, 9, 10] _.range(0, 100, 20); // => [0, 20, 40, 60, 80] _.range(0, -7, -1) -
range _.range(7); // => [0, 1, 2, 3, 4, 5,
6] _.range(5, 11); // => [5, 6, 7, 8, 9, 10] _.range(0, 100, 20); // => [0, 20, 40, 60, 80] _.range(0, -7, -1) // => [0, -1, -2, -3, -4, -5, -6]