Skip to content

Instantly share code, notes, and snippets.

def crazy_sum(numbers)
i = 0
sum = 0
while i < numbers.length
spot = numbers[i]
product = i * spot
sum = sum + product
i+=1
end
return sum
def crazy_sum(numbers)
i = 0
sum = 0
while i < numbers.length
spot = numbers[i]
product = i * spot
sum = sum + product
i+=1
end
return sum
require "./contact.rb"
class AddressBook
attr_reader :contacts
def initialize
@contacts = []
end
def run
loop do
def find_by_address(query)
results = []
search = query.downcase
contacts.each do |contact|
contact.addresses.each do |address|
if address.to_s('long').downcase.include?(search)
results.push(contact) unless results.include?(contact)
end
end
end
def find_by_address(query)
results = []
search = query.downcase
contacts.each do |contact|
contact.addresses.each do |address|
if address.to_s('long').downcase.include?(search)
results.push(contact) unless results.include?(contact)
end
end
end
# Write a method that takes in a string and returns the number of
# letters that appear more than once in the string. You may assume
# the string contains only lowercase letters. Count the number of
# letters that repeat, not the number of times they repeat in the
# string.
# Loi Tran
#
# Difficulty: hard.
# crazy_sum
# Write a method named crazy_sum(numbers) that takes an array of numbers. crazy_sum should multiply each number
# in the array by its position in the array, and return the sum.
# Make sure your code works for arrays with repeats of the same number (like [2, 3, 5, 2]).
# Hint: be careful about using Array #index; why?
def crazy_sum(array)
i = 0
# Write a method that takes in a string and returns the number of
# letters that appear more than once in the string. You may assume
# the string contains only lowercase letters. Count the number of
# letters that repeat, not the number of times they repeat in the
# string.
# Loi Tran
#
# Difficulty: hard.
# Write a method that takes in a number and returns a string, placing
# a single dash before and after each odd digit. There is one
# exception: don't start or end the string with a dash.
#
# You may wish to use the `%` modulo operation; you can see if a number
# is even if it has zero remainder when divided by two.
#
# Loi Tran
# 12/15/15
# Write a method that takes in a number and returns a string, placing
# a single dash before and after each odd digit. There is one
# exception: don't start or end the string with a dash.
#
# You may wish to use the `%` modulo operation; you can see if a number
# is even if it has zero remainder when divided by two.
#
# Loi Tran
# 12/15/15