Walkthrough

Solutions

def palindrome?(str)
  str == str.reverse
end

def boolean_to_binary(arr)
  binary = ""

  arr.each do |boolean|
    if boolean
      binary += "1"
    else
      binary += "0"
    end
  end

  binary
end

# Alternate solution using a while-loop

def boolean_to_binary(arr)
  str = ''
  i = 0
  while i < arr.length
    if arr[i]
      str << "1"
    else
      str << "0"
    end
    i += 1
  end
  str
end

def third_largest(arr)
  arr.sort[-3]
end

def format_time(num)
  if num < 10
    "0" + num.to_s
  else
    num.to_s
  end
end

def time_conversion(mins)
  hours = mins / 60
  mins = mins % 60
  format_time(hours) + ":" + format_time(mins)
end

results matching ""

    No results matching ""