Practice Coding Exercise

lucky_sevens?

Write a function lucky_sevens?(numbers), which takes in an array of integers and returns true if any three consecutive elements sum to 7.

lucky_sevens?([2,1,5,1,0]) == true # => 1 + 5 + 1 == 7
lucky_sevens?([0,-2,1,8]) == true # => -2 + 1 + 8 == 7
lucky_sevens?([7,7,7,7]) == false
lucky_sevens?([3,4,3,4]) == false

Make sure your code correctly checks for edge cases (i.e. the first and last elements of the array).

My solution:

screen-shot-2016-11-10-at-1-54-13-pm

oddball_sum

Write a function oddball_sum(numbers), which takes in an array of integers and returns the sum of all the odd elements.

oddball_sum([1,2,3,4,5]) == 9 # => 1 + 3 + 5 == 9
oddball_sum([0,6,4,4]) == 0
oddball_sum([1,2,1]) == 2

My solution:

Screen Shot 2016-11-10 at 1.54.42 PM.png

disemvowel

Write a function disemvowel(string), which takes in a string, and returns that string with all the vowels removed. Treat “y” as a consonant.

disemvowel("foobar") == "fbr"
disemvowel("ruby") == "rby"
disemvowel("aeiou") == ""

My solution:

Screen Shot 2016-11-10 at 1.55.56 PM.png

 

I did these with 26 mins remaining on the clock! (I was given 45min total.)

Advertisements
Practice Coding Exercise

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s