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.

``````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.

``````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.

`````` 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.

Here's the thing. https://www.google.com/search?q=Write+a+function+lucky_sevens%3F%28numbers%29%2C+which+takes+in+an+array+of+integers+and+returns+true+if+any+three+consecutive+elements+sum+to+7.&ie=utf-8&oe=utf-8 finds priors and I think this is homework or coding challenges.

As to your idea to port your python code, since you have a spec on what to write, do that instead from scratch in Ruby. If you need to get back to the books or web on Ruby, then do that. But don't let what you wrote in Python dictate how to do such in Ruby.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.