try ruby Flashcards
(156 cards)
reverse a string
.reverse
length of a string
.length
print string x times
”” * X
reverse number
1.to_s.reverse
to string
.to_s
to integer
to_i
to array
to_a
declare array / assign array
[] / x=[1,2,3]
[] creates an empty what
list
does a list store thing out of order
false
get max from array
.max
sort array
.sort!
method with ! does what
changes value for good
replace all string x in an array containing x
arr[‘x’]=’y’
reverse an array with a string of lines, (only each individual line) without writing words backwards
poem.lines.to_a.reverse
join elements in an array
.join
check to see if something is included
.include?
lowercase everything
.downcase
delete an obj
.delete
dictionary or hash
books={}
add elements to a dictionary/hash
books[“title”] = :splendid
can you use length on a dictionary/hash?
yes, will return number of items within
iterate through a dictionary/hash’s values
books.values.each{|rate| ratings[rate]}
iterate and count number of times rate appears through a dictionary/hash’s values
books.values.each{|rate| ratings[rate]+=1}
returns like {:good=>2, :bad:=>5}