This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "./contact.rb" | |
class AddressBook | |
attr_reader :contacts | |
def initialize | |
@contacts = [] | |
end | |
def run | |
loop do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
NewerOlder