Quotes help make search much faster. Example: "Practice Makes Perfect"

Wednesday, November 21, 2012

Codecademy: "Sorting With Control Flow"


#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)

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts