w1d1 Flashcards

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

A

array.sample

21
Q

arrays should always contain one type of something

A

true

22
Q

TQ: remove duplicates from array

A

enter

23
Q

TQ: sum of two positions in array that equal zero

A

enter

24
Q

TQ: Tower of Hanoi

A

enter

25
Q

TQ: My Transpose

convert square grid rows to col

A

enter

26
Q

TQ: Stock Picker

A

enter

27
Q

escape character example

A

\n, \, ", '

28
Q

reverse order of string

A

string.reverse

29
Q

uppercase string

A

string.upsace

30
Q

lowercase string

A

string.downcase

31
Q

appending string

A

string &laquo_space;“another string”

does not create new string object. it just modifies existing one

32
Q

access substring

A

string[5..6]

33
Q

string length

A

string.length

34
Q

split string into arrays

A

string. split(“, “) split by comma

string. split(“ “) split by space

35
Q

nil.to_s

A

””