Walkthrough

Solutions

def is_slippery?(n)
  (n % 3 == 0 || n % 5 == 0) && n % 15 != 0
end

def slippery_numbers(n)
  slippery_array = []
  current_number = 1

  until slippery_array.length == n
    slippery_array << current_number if is_slippery?(current_number)
    current_number += 1
  end

  slippery_array
end

def e_words(str)
  words = str.split
  count = 0

  words.each do |word|
    count += 1 if word[-1] == "e"
  end

  count
end

# Here's another way to solve e_words using a while-loop

def e_words(str)
  words = str.split
  count = 0
  i = 0

  while i < words.length
    if words[i][-1] == "e"
      count += 1
    end
    i += 1
  end

  count    
end

def fibs(n)
  fibbys = [0, 1]
  return fibbys.take(n) if n < 3

  until fibbys.length == n
    fibbys << fibbys[-2] + fibbys[-1]
  end

  fibbys
end

results matching ""

    No results matching ""