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. Your method should return the | |
# most common letter in the array, and a count of how many times it | |
# appears. | |
# | |
# Difficulty: medium. | |
def most_common_letter(string) | |
i=0 | |
j=0 | |
frequency=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 an array of numbers in. Your method should | |
# return the third greatest number in the array. You may assume that | |
# the array has at least three numbers in it. | |
# | |
# Difficulty: medium. | |
def third_greatest(nums) | |
sorted_nums=[] | |
new_nums=[] | |
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 an array of numbers in. Your method should | |
# return the third greatest number in the array. You may assume that | |
# the array has at least three numbers in it. | |
# | |
# Difficulty: medium. | |
def third_greatest(nums) | |
sorted_nums=nums.sort | |
return sorted_nums[nums.length-3] |
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 true if it is a | |
# power of 2. Otherwise, return false. | |
# | |
# You may want to use the `%` modulo operation. `5 % 2` returns the | |
# remainder when dividing 5 by 2; therefore, `5 % 2 == 1`. In the case | |
# of `6 % 2`, since 2 evenly divides 6 with no remainder, `6 % 2 == 0`. | |
# | |
# Difficulty: medium. | |
def is_power_of_two?(num) |
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 an array of numbers. If a pair of numbers | |
# in the array sums to zero, return the positions of those two numbers. | |
# If no pair of numbers sums to zero, return `nil`. | |
# | |
# Difficulty: medium. | |
def two_sum(nums) | |
pos=[] | |
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 a string in and returns true if the letter | |
# "z" appears within three letters **after** an "a". You may assume | |
# that the string contains only lowercase letters. | |
# | |
# Difficulty: medium. | |
def nearby_az(string) | |
i=0 | |
a_pos=0 | |
while i<string.length |
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 a string and returns true if it is a | |
# palindrome. A palindrome is a string that is the same whether written | |
# backward or forward. Assume that there are no spaces; only lowercase | |
# letters will be given. | |
# | |
# Difficulty: easy. | |
def palindrome?(string) | |
i=0 | |
palindrome_or_no=true |
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 a string and returns the number of vowels | |
# in the string. You may assume that all the letters are lower cased. | |
# You can treat "y" as a consonant. | |
# | |
# Difficulty: easy. | |
def count_vowels(string) | |
i=0 | |
num_vowels=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 will take in a number of minutes, and returns a | |
# string that formats the number into `hours:minutes`. | |
# | |
# Difficulty: easy. | |
def time_conversion(minutes) | |
hour=0 | |
mins=0 | |
string_hr_mins="" | |
hour=minutes/60 |
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 an integer `num` and returns the sum of | |
# all integers between zero and num, up to and including `num`. | |
# | |
# Difficulty: easy. | |
def sum_nums(num) | |
sum=0 | |
i=0 | |
while i<num+1 | |
sum=sum+i |
NewerOlder