#sample solution
def alphabetize(arr, rev=false)
if rev
arr.sort! {|item1, item2| item2 <=> item1}
else
arr.sort! {|item1, item2| item1 <=> item2}
end
end
puts alphabetize(["b","a","d","c"])
puts #space
puts alphabetize(["b","a","d","c"],true)
def alphabetize(arr, rev=false)
if rev
arr.sort! {|item1, item2| item2 <=> item1}
else
arr.sort! {|item1, item2| item1 <=> item2}
end
end
puts alphabetize(["b","a","d","c"])
puts #space
puts alphabetize(["b","a","d","c"],true)
No comments:
Post a Comment