Arrayology Flashcards

1
Q

Add element to end of array

A

array.push(element)

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

Remove and return element from end of array

A

array.pop(element)

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

Add element to beginning of array

A

array.unshift(element)

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

Remove and return element from beginning of array

A

array.shift(element)

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

Find the first instance of a value

A

array.indexOf(value)

Optional second argument specifies where to start searching from.

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

Find the last instance of a value

A

array.lastIndexOf(value)

Optional second argument specifies where to start searching from.

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

Get me a copy of the elements between some indices

A

array.slice(start, stop)
Start is inclusive, stop exclusive. If either is omitted, the slice starts at 0 or ends at the last element, respectively.

String slicing works the same.

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

How do I glue two arrays together

A

array.concat(other_array)

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

String indexing??

A

string. indexOf(substring)
- -> Note: the argument for indexOf may be a whole substring, and indexOf will return the index of the start of the substring.

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

How can I remove whitespace from a string?

A

string.trim()

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

What about the length of an array or object or string?

A

array. length
string. length
object. length

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

Reverse an array in place?

A

array.reverse()

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

Apply a function to each element of an array?

A

array.forEach(function)

NOTE: the function may be user-defined, may even be defined on the spot in the call to forEach.

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

Sift through the elements of an array?

A

array.filter(function) –> returns a new array with the elements of the original array for which the function argument returns true.

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

Transform an array?

A

array.map(function) –> returns a new array created by applying the function to each element of the original.

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

‘Sum up’ an array?

A

array.reduce(function) –> will return a single value, the result of applying the binary function to each set of values in the array.

17
Q

The fundamental higher-order functions on arrays

A
forEach
map
filter
reduce
bind
every
some
18
Q

How do I know if every element of an array has a property?

A

array.every(predicate) –> returns true iff every element of the array returns true when evaluated by the predicate function.

19
Q

How do I know if there is at least one element of an array with a given property?

A

array.some(predicate) –> returns true iff some element of the array evaluates as true when tested by the predicate function