Arrays Flashcards

1
Q

_.first(array, [n])

A

Returns the first element of an array. Passing n will return the first n elements of the array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

_.initial(array, [n])

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

_.last(array, [n])

A

Returns the last element of an array. Passing n will return the last n elements of the array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

_.rest(array, [index])

A

Returns the rest of the elements in an array. Pass an index to return the values of the array from that index onward.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

_.compact(array)

A

Returns a copy of the array with all falsy values removed. In JavaScript, false, null, 0, “”, undefined and NaN are all falsy.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

_.flatten(array, [shallow])

A

Flattens a nested array (the nesting can be to any depth). If you pass shallow, the array will only be flattened a single level.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

_.without(array, *values)

A

Returns a copy of the array with all instances of the values removed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

_.union(*arrays)

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

_.intersection(*arrays)

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

_.difference(array, *others)

A

Returns the values from array that are not present in the other arrays.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

_.uniq(array, [isSorted], [iteratee])

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

_.zip(*arrays)

A

Merges together the values of each of the arrays with the values at the corresponding position. Useful when you have separate data sources that are coordinated through matching array indexes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

_.unzip(*arrays)

A

Given a number of arrays, returns a series of new arrays, the first of which contains all of the first elements in the input arrays, the second of which contains all of the second elements, and so on.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

_.object(list, [values])

A

Converts arrays into objects. Pass either a single list of [key, value] pairs, or a list of keys, and a list of values. If duplicate keys exist, the last value wins.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

_.indexOf(array, value, [isSorted])

A

Returns the index at which value can be found in the array, or -1 if value is not present in the array. If you’re working with a large array, and you know that the array is already sorted, pass true for isSorted to use a faster binary search

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

_.lastIndexOf(array, value, [fromIndex])

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

_.sortedIndex(list, value, [iteratee], [context])

A

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.

18
Q

_.findIndex(array, predicate, [context])

A

Similar to _.indexOf, returns the first index where the predicate truth test passes; otherwise returns -1.

19
Q

_.findLastIndex(array, predicate, [context])

A

Like _.findIndex but iterates the array in reverse, returning the index closest to the end where the predicate truth test passes.

20
Q

_.range([start], stop, [step])

A

A function to create flexibly-numbered lists of integers, handy for each and map loops. start, if omitted, defaults to 0; step defaults to 1. Returns a list of integers from start (inclusive) to stop (exclusive), incremented (or decremented) by step, exclusive. Note that ranges that stop before they start are considered to be zero-length instead of negative — if you’d like a negative range, use a negative step.

21
Q

Returns the first element of an array. Passing n will return the first n elements of the array.

A

_.first(array, [n])

22
Q

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.

A

_.initial(array, [n])

23
Q

Returns the last element of an array. Passing n will return the last n elements of the array.

A

_.last(array, [n])

24
Q

Returns the rest of the elements in an array. Pass an index to return the values of the array from that index onward.

A

_.rest(array, [index])

25
Q

Returns a copy of the array with all falsy values removed. In JavaScript, false, null, 0, “”, undefined and NaN are all falsy.

A

_.compact(array)

26
Q

Flattens a nested array (the nesting can be to any depth). If you pass shallow, the array will only be flattened a single level.

A

_.flatten(array, [shallow])

27
Q

Returns a copy of the array with all instances of the values removed.

A

_.without(array, *values)

28
Q

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.

A

_.union(*arrays)

29
Q

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.

A

_.intersection(*arrays)

30
Q

Returns the values from array that are not present in the other arrays.

A

_.difference(array, *others)

31
Q

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.

A

_.uniq(array, [isSorted], [iteratee])

32
Q

Merges together the values of each of the arrays with the values at the corresponding position. Useful when you have separate data sources that are coordinated through matching array indexes.

A

_.zip(*arrays)

33
Q

Given a number of arrays, returns a series of new arrays, the first of which contains all of the first elements in the input arrays, the second of which contains all of the second elements, and so on.

A

_.unzip(*arrays)

34
Q

Converts arrays into objects. Pass either a single list of [key, value] pairs, or a list of keys, and a list of values. If duplicate keys exist, the last value wins.

A

_.object(list, [values])

35
Q

Returns the index at which value can be found in the array, or -1 if value is not present in the array. If you’re working with a large array, and you know that the array is already sorted, pass true for isSorted to use a faster binary search

A

_.indexOf(array, value, [isSorted])

36
Q

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.

A

_.lastIndexOf(array, value, [fromIndex])

37
Q

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.

A

_.sortedIndex(list, value, [iteratee], [context])

38
Q

Similar to _.indexOf, returns the first index where the predicate truth test passes; otherwise returns -1.

A

_.findIndex(array, predicate, [context])

39
Q

Like _.findIndex but iterates the array in reverse, returning the index closest to the end where the predicate truth test passes.

A

_.findLastIndex(array, predicate, [context])

40
Q

A function to create flexibly-numbered lists of integers, handy for each and map loops. start, if omitted, defaults to 0; step defaults to 1. Returns a list of integers from start (inclusive) to stop (exclusive), incremented (or decremented) by step, exclusive. Note that ranges that stop before they start are considered to be zero-length instead of negative — if you’d like a negative range, use a negative step.

A

_.range([start], stop, [step])