Array Flashcards

1
Q

Ruby Array

return the first n elements of an array

A

take(n) => new_ary

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

Ruby Array

return a new array containing elements common to the two arrays

A

ary & other_ary => new_ary

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

Ruby Array

return a new array built by concatenating the two arrays together to produce a third array

A

concat(other_ary) => ary

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

Ruby Array

return a new array that is a copy of the original array, removing any items that also appear in other_ayr

A

ary - other_ary => new_ary

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

Ruby Array

append - pushes the given object to the end of this array

A

ary << obj => ary

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

Ruby Array

search through an array whose elements are also arrays comparing obj with the first element of each contained array; return the first contained array that matches, or nil if no match is found

A

assoc(obj) => element_ary or nil

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

Ruby Array

return the element at index; a negative index counts from the end of self; return nil if the index is out of range

A

at(index) => obj or nil

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

Ruby Array

remove all elements of self

A

clear => ary

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

Ruby Array

yield all combinations of length n of elements from the array

A

combination(n) => Enumerator

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

Ruby Array

return a copy of self with all nil elements removed

A

compact => new_ary

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

Ruby Array

alias for Array#concat

A

ary + other_ary => new_ary

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

Ruby Array

return the number of elements; if an argument is given, return the number of elements that == obj; if a block is given, return the number of elements for which the block returns true

A

count => int

count(obj) => int

count { |item| block } => int

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

Ruby Array

call the given block n times for each element or forever if nil is given

A

cycle(n=nil) { |obj| block }

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

Ruby Array

delete all items from self that == obj

A

delete(obj) => item or nil

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

Ruby Array

delete the element at the specified index, returning that element or nil if the index is out of range

A

delete_at(index) => obj or nil

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

Ruby Array

return a new array containing elements in self for which the given block is not true

A

reject { |item| block } => new_ary

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

Ruby Array

drop first n elements from ary and returns the remaining elements in an array

A

drop(n) => new_ary

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

Ruby Array

drop elements up to, but not including, the first element for which the block returns nil or false and return an array containing the remaining elements

A

drop_while { |obj| block } => new_ary

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

Ruby Array

call the given block once for each element in self, passing that element as a parameter; return the array itself

A

each { |item| block } => ary

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

Ruby Array

same as Array#each, but passes the index of the element instead of the element itself

A

each_index { |index| block } => ary

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

Ruby Array

return true if self contains no elements

A

empty? => true or false

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

Ruby Array

set the selected elements of self to obj; if a block is given, fills the array with the value of the block, which is passed the index of each element to be filled

A

fill(obj) => ary

fill(obj, start [, length]) => ary

fill(obj, range) => ary

fill { |index| block } => ary

fill(start [, length]) { |index| block} => ary

fill(range) { |index| block } => ary

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

Ruby Array

return the index of the first element that == obj; if a block is given, return the index of the first element for which the block returns true

A

find_index(obj) => int or nil

find_index { |item| block } => int or nil

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

Ruby Array

return the first n elements of self

A

first => obj or nil

first(n) => new_ary

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
# Ruby Array return a new array that is a one-dimensional flattening of self; optional level argument determines the level of recursion to flatten
flatten =\> new\_ary flatten(level) =\> new\_ary
26
# Ruby Array return true if obj is present in self (any element == obj)
include?(obj) =\> true or false
27
# Ruby Array return the index of the first element of self that == obj; if a block is given, return the first element for which the block returns true
index(obj) =\> int or nil index { |item| block } =\> int or nil
28
# Ruby Array insert the given values before the element at the specified index; if a negative index is given, the elements are inserted after the element that index (i.e. -1 adds to the end of the array)
insert(index, obj...) =\> ary
29
# Ruby Array return a string created by converting each element of self to a string, separated by the given separator or an empty string
join(separator=$,) =\> str
30
# Ruby Array return the last n elements of self
last =\> obj or nil last(n) =\> new\_ary
31
# Ruby Array return the number of elements in self
length =\> int
32
# Ruby Array return a new array containing the values returned by the block, which is invoked once for each element of self
map { |item| block } =\> new\_ary
33
# Ruby Array yield all permutations of length n of the elements of self, then return the array itself
permutation(n) =\> Enumerator permutation(n) { |p| block } =\> ary
34
# Ruby Array remove the last n elements of self and return them
pop =\> obj or nil pop(n) =\> new\_ary
35
# Ruby Array return an array of all combinations of elements of all arrays
product(other\_ary, ...) =\> new\_ary
36
# Ruby Array append - push the given object(s) on to the end of self, returning the array itself
push(obj, ...) =\> ary
37
# Ruby Array search through self whose elements are also arrays; compare obj with the second element of each contained array; return the first contained array that matches obj
rassoc(obj) =\> element or nil
38
# Ruby Array yield all repeated combinations of length n of elements of self then returns the array itself
repeated\_combination(n) =\> Enumerator
39
# Ruby Array yield all repeated permuations of length n of the elements of self, then return the array itself
repeated\_permutation(n) =\> Enumerator
40
# Ruby Array return a new array containing self's elements in reverse order
reverse =\> new\_ary
41
# Ruby Array same as Array#each but traverses self in reverse order
reverse\_each { |item| block } =\> ary
42
# Ruby Array return the index of the last element in self that == obj; if a block is given, return the index of the last element in self for which the block returns true
rindex(obj) =\> int or nil rindex(obj) { |item| block } =\> int or nil
43
# Ruby Array return a new array by rotating self so that the element at count is the first element of the new array
rotate(count=1) =\> new\_ary
44
# Ruby Array choose a random element or n random elements from self
sample =\> obj sample(n) =\> new\_ary
45
# Ruby Array return a new array containing all elements of self for which the block returns a true value
select { |item| block } =\> new\_ary
46
# Ruby Array remove the first element of self and returns it (shifting all other elements down by one); returns nil if empty
shift =\> obj
47
# Ruby Array return a new array with the elements of self shuffled
shuffle =\> new\_ary
48
# Ruby Array return a new array created by sorting self; comparisons done using ; if a block is given, it must implement a comparison between a and b and return a negative integer if a
sort =\> new\_ary sort { |a, b| block } =\> new\_ary
49
# Ruby Array return the first n elements of self
take(n) =\> new\_ary
50
# Ruby Array pass elements of self to the block until the block returns nil or false; returns an array of all prior elements
take\_while { |obj| block } =\> new\_ary
51
# Ruby Array assume that self is an array of arrays and transposes rows and columns
transpose =\> new\_ary
52
# Ruby Array return a new array by removing duplicate values in self; if a block is given, use the return value of the block for comparison
uniq =\> new\_ary uniq { |item| block } =\> new\_ary
53
# Ruby Array prepend obj to the front of self, moving other elements upwards
unshift(obj, ...) =\> ary
54
# Ruby Array convert any arguments to arrays, then merges elements of self with corresponding elements from each argument; if a block is given, it's invoked for each output array, otherwise an array of arrays is returned
zip(arg, ...) =\> new\_ary zip(arg, ...) { |arr| block } =\> nil
55
# Ruby Array set union - return a new array by joining ary and other\_ary, excluding any duplicates and preserving the order from the original array
ary | other\_ary =\> new\_ary
56
# Ruby Array take(n) =\> new\_ary
return the first n elements of an array
57
# Ruby Array ary & other\_ary =\> new\_ary
return a new array containing elements common to the two arrays
58
# Ruby Array concat(other\_ary) =\> ary
return a new array built by concatenating the two arrays together to produce a third array
59
# Ruby Array ary - other\_ary =\> new\_ary
return a new array that is a copy of the original array, removing any items that also appear in other\_ayr
60
# Ruby Array ary \<\< obj =\> ary
append - pushes the given object to the end of this array
61
# Ruby Array assoc(obj) =\> element\_ary or nil
search through an array whose elements are also arrays comparing obj with the first element of each contained array; return the first contained array that matches, or nil if no match is found
62
# Ruby Array at(index) =\> obj or nil
return the element at index; a negative index counts from the end of self; return nil if the index is out of range
63
# Ruby Array clear =\> ary
remove all elements of self
64
# Ruby Array combination(n) =\> Enumerator
yield all combinations of length n of elements from the array
65
# Ruby Array compact =\> new\_ary
return a copy of self with all nil elements removed
66
# Ruby Array ary + other\_ary =\> new\_ary
alias for Array#concat
67
# Ruby Array count =\> int count(obj) =\> int count { |item| block } =\> int
return the number of elements; if an argument is given, return the number of elements that == obj; if a block is given, return the number of elements for which the block returns true
68
# Ruby Array cycle(n=nil) { |obj| block }
call the given block n times for each element or forever if nil is given
69
# Ruby Array delete(obj) =\> item or nil
delete all items from self that == obj
70
# Ruby Array delete\_at(index) =\> obj or nil
delete the element at the specified index, returning that element or nil if the index is out of range
71
# Ruby Array reject { |item| block } =\> new\_ary
return a new array containing elements in self for which the given block is not true
72
# Ruby Array drop(n) =\> new\_ary
drop first n elements from ary and returns the remaining elements in an array
73
# Ruby Array drop\_while { |obj| block } =\> new\_ary
drop elements up to, but not including, the first element for which the block returns nil or false and return an array containing the remaining elements
74
# Ruby Array each { |item| block } =\> ary
call the given block once for each element in self, passing that element as a parameter; return the array itself
75
# Ruby Array each\_index { |index| block } =\> ary
same as Array#each, but passes the index of the element instead of the element itself
76
# Ruby Array empty? =\> true or false
return true if self contains no elements
77
# Ruby Array fill(obj) =\> ary fill(obj, start [, length]) =\> ary fill(obj, range) =\> ary fill { |index| block } =\> ary fill(start [, length]) { |index| block} =\> ary fill(range) { |index| block } =\> ary
set the selected elements of self to obj; if a block is given, fills the array with the value of the block, which is passed the index of each element to be filled
78
# Ruby Array find\_index(obj) =\> int or nil find\_index { |item| block } =\> int or nil
return the index of the first element that == obj; if a block is given, return the index of the first element for which the block returns true
79
# Ruby Array first =\> obj or nil first(n) =\> new\_ary
return the first n elements of self
80
# Ruby Array flatten =\> new\_ary flatten(level) =\> new\_ary
return a new array that is a one-dimensional flattening of self; optional level argument determines the level of recursion to flatten
81
# Ruby Array include?(obj) =\> true or false
return true if obj is present in self (any element == obj)
82
# Ruby Array index(obj) =\> int or nil index { |item| block } =\> int or nil
return the index of the first element of self that == obj; if a block is given, return the first element for which the block returns true
83
# Ruby Array insert(index, obj...) =\> ary
insert the given values before the element at the specified index; if a negative index is given, the elements are inserted after the element that index (i.e. -1 adds to the end of the array)
84
# Ruby Array join(separator=$,) =\> str
return a string created by converting each element of self to a string, separated by the given separator or an empty string
85
# Ruby Array last =\> obj or nil last(n) =\> new\_ary
return the last n elements of self
86
# Ruby Array length =\> int
return the number of elements in self
87
# Ruby Array map { |item| block } =\> new\_ary
return a new array containing the values returned by the block, which is invoked once for each element of self
88
# Ruby Array permutation(n) =\> Enumerator permutation(n) { |p| block } =\> ary
yield all permutations of length n of the elements of self, then return the array itself
89
# Ruby Array pop =\> obj or nil pop(n) =\> new\_ary
remove the last n elements of self and return them
90
# Ruby Array product(other\_ary, ...) =\> new\_ary
return an array of all combinations of elements of all arrays
91
# Ruby Array push(obj, ...) =\> ary
append - push the given object(s) on to the end of self, returning the array itself
92
# Ruby Array rassoc(obj) =\> element or nil
search through self whose elements are also arrays; compare obj with the second element of each contained array; return the first contained array that matches obj
93
# Ruby Array repeated\_combinations(n) =\> Enumerator
yield all repeated combinations of length n of elements of self then returns the array itself
94
# Ruby Array repeated\_permutation(n) =\> Enumerator
yield all repeated permuations of length n of the elements of self, then return the array itself
95
# Ruby Array reverse =\> new\_ary
return a new array containing self's elements in reverse order
96
# Ruby Array reverse\_each { |item| block } =\> ary
same as Array#each but traverses self in reverse order
97
# Ruby Array rindex(obj) =\> int or nil rindex(obj) { |item| block } =\> int or nil
return the index of the last element in self that == obj; if a block is given, return the index of the last element in self for which the block returns true
98
# Ruby Array rotate(count=1) =\> new\_ary
return a new array by rotating self so that the element at count is the first element of the new array
99
# Ruby Array sample =\> obj sample(n) =\> new\_ary
choose a random element or n random elements from self
100
# Ruby Array select { |item| block } =\> new\_ary
return a new array containing all elements of self for which the block returns a true value
101
# Ruby Array shift =\> obj
remove the first element of self and returns it (shifting all other elements down by one); returns nil if empty
102
# Ruby Array shuffle =\> new\_ary
return a new array with the elements of self shuffled
103
# Ruby Array sort =\> new\_ary sort { |a, b| block } =\> new\_ary
return a new array created by sorting self; comparisons done using ; if a block is given, it must implement a comparison between a and b and return a negative integer if a
104
# Ruby Array take(n) =\> new\_ary
return the first n elements of self
105
# Ruby Array take\_while { |obj| block } =\> new\_ary
pass elements of self to the block until the block returns nil or false; returns an array of all prior elements
106
# Ruby Array transpose =\> new\_ary
assume that self is an array of arrays and transposes rows and columns
107
# Ruby Array uniq =\> new\_ary uniq { |item| block } =\> new\_ary
return a new array by removing duplicate values in self; if a block is given, use the return value of the block for comparison
108
# Ruby Array unshift(obj, ...) =\> ary
prepend obj to the front of self, moving other elements upwards
109
# Ruby Array zip(arg, ...) =\> new\_ary zip(arg, ...) { |arr| block } =\> nil
convert any arguments to arrays, then merges elements of self with corresponding elements from each argument; if a block is given, it's invoked for each output array, otherwise an array of arrays is returned
110
# Ruby Array ary | other\_ary =\> new\_ary
set union - return a new array by joining ary and other\_ary, excluding any duplicates and preserving the order from the original array