so i am trying to convert my python codes into RUBY. Can someone please help me do that...
1- Write a function lucky_sevens?(numbers), which takes in an array of integers and returns true if any three consecutive elements sum to 7.
My python answer:
def lucky_sevens(numbers):
for index in range(len(numbers)-2): #will only look for 3 elements
sum = numbers[index] + numbers[index+1] + numbers[index+2] #adds up any 3 consecutive elements
if sum == 7:
return True
return False
Ruby answer: I really can't figure out how to write it in ruby, but i did this, im pretty sure its also wrong
idx = 0
for idx < arr.length
sum = arr[0] + arr[1] + arr[2]
if sum == 7
puts("true")
end
2-Write a function oddball_sum(numbers), which takes in an array of integers and returns the sum of all the odd elements.
My python answer:
def oddball_sum (numbers):
total=0
for element in oddball_sum:
if element%2: #verifies if the number is odd
total += element
Ruby? No idea
3-Write a function disemvowel(string), which takes in a string, and returns that string with all the vowels removed. Treat "y" as a consonant.
My python answer:
def disemvowel(string):
vowels = "aeiou"
new_string = ""
for letter in word: #checks the letters in word list
if letter.lower() not in vowels:
new_string += letter
I do not know how to write it in RUBY... Though i am learning all the basics, so far i have learned puts, gets, chomp, push, unshift etc functions. but it seems different to me.
Thank you for your answer!