w1d1 Flashcards

(35 cards)

1
Q

creating arrays

A
empty_array = Array.new
empty_array = []
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

accessing item by index (array)

A

some_fruits = [“pear”, “apple”]
some_fruits[0]
some_fruits[-1] from end

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

array ‘range’ example

A

some_fruits[0..1], some_fruits[0…2]
.. => start to finish
… => start to, but not including finish

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

accessing elements in order

A

array.each do |thing|

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

you should never modify array during iteration

A

true

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

setting and adding elements (array)

A

array[1] = “something else”
array &laquo_space;“something”
array.push “something”

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

array + array

A

creates a new array that hold both values

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

add two arrays without ‘+’

A

array.concat(array_other)

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

array size example

A

array.count

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

check if array is empty

A

array.empty?

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

push pop array

A

array &laquo_space;“something”

array.pop

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

array as queue example

A

array &laquo_space;elements
array.shift
(first in, first out)

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

push element in front of array

A

array.unshift

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

interpolation

A

execute code in #{} inside string

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

finding elements in array

A

array.include?(something)

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

finding index of element in array

A

array.index(something)

17
Q

sorting an array

A

array. sort (returns new array)

array. sort! (modifies array)

18
Q

randomize order of array

A

array.shuffle

19
Q

access first and last element of array

A

array. first

array. last

20
Q

select element at random in array

21
Q

arrays should always contain one type of something

22
Q

TQ: remove duplicates from array

23
Q

TQ: sum of two positions in array that equal zero

24
Q

TQ: Tower of Hanoi

25
TQ: My Transpose | convert square grid rows to col
enter
26
TQ: Stock Picker
enter
27
escape character example
\n, \\, \", \'
28
reverse order of string
string.reverse
29
uppercase string
string.upsace
30
lowercase string
string.downcase
31
appending string
string << "another string" | does not create new string object. it just modifies existing one
32
access substring
string[5..6]
33
string length
string.length
34
split string into arrays
string. split(", ") split by comma | string. split(" ") split by space
35
nil.to_s
""