Skip to content

Instantly share code, notes, and snippets.

@RickGriff
RickGriff / jenny_message.rb
Created December 11, 2017 21:57
Codewars Challenge 1 - Jenny's Secret Message
#Jenny has written a function that returns a greeting for a user. However, she's in love with Johnny, and would
#like to greet him slightly different. She added a special case to her function, but she made a mistake.
#Can you help her?
#Initial Code with Error:
def greet(name)
return "Hello, #{name}!"
return "Hello, my love!" if name == "Johnny"
end
@RickGriff
RickGriff / stringy_strings.rb
Created December 11, 2017 22:02
Codewars Challenge 3 - Stringy Strings
#write me a function stringy that takes a size and returns a string of alternating '1s' and '0s'.
#the string should start with a 1.
#a string with size 6 should return :'101010'.
#with size 4 should return : '1010'.
#with size 12 should return : '101010101010'.
#The size will always be positive and will only use whole numbers.
#My Solution:
@RickGriff
RickGriff / title_case.rb
Created January 21, 2018 21:27
Codewars Challenge: Title Case
# A string is considered to be in title case if each word in the string is either (a) capitalised (that is, only the first letter of the word is in upper case) or (b) considered to be an exception and put entirely into lower case unless it is the first word, which is always capitalised.
# Write a function that will convert a string into title case, given an optional list of exceptions (minor words). The list of minor words will be given as a string with each word separated by a space.
# Your function should ignore the case of the minor words string -- it should behave in the same way even if the case of the minor word string is changed.
# ###Arguments (Haskell)
# First argument: space-delimited list of minor words that must always be lowercase except for the first word in the string.
# Second argument: the original string to be converted.
# ###Arguments (Other languages)
@RickGriff
RickGriff / evil_autocorrect.rb
Created January 21, 2018 21:22
Codewars Challenge: Evil Autocorrect Prank
# Your friend won't stop texting his girlfriend. It's all he does. All day. Seriously. The texts are so mushy too! The whole situation just makes you feel ill. Being the wonderful friend that you are, you hatch an evil plot. While he's sleeping, you take his phone and change the autocorrect options so that every time he types "you" or "u" it gets changed to "your sister."
# Write a function called autocorrect that takes a string and replaces all instances of "you" or "u" (not case sensitive) with "your sister" (always lower case).
# Return the resulting string.
# Here's the slightly tricky part: These are text messages, so there are different forms of "you" and "u".
# For the purposes of this kata, here's what you need to support:
@RickGriff
RickGriff / spinwords.rb
Last active January 21, 2018 21:19
Codewars Challenge: Stop gninnipS My sdroW!
#Write a function that takes in a string of one or more words, and Drop one or more filereturns the same string, but with all
#five or more letter words reversed (Just like the name of this Kata).
#Strings passed in will consist of only letters and spaces.
#Spaces will be included only when more than one word is present.
#Examples:
#spinWords( "Hey fellow warriors" ) => returns "Hey wollef sroirraw"
#spinWords( "This is a test") => returns "This is a test"
#spinWords( "This is another test" )=> returns "This is rehtona test"
@RickGriff
RickGriff / format_names.rb
Last active January 21, 2018 21:17
Codewars Challenge: Format Names
# Given: an array containing hashes of names
# Return: a string formatted as a list of names separated by commas except for the last two names, which should be separated by an ampersand.
# Example:
# list([ {name: 'Bart'}, {name: 'Lisa'}, {name: 'Maggie'} ])
# # returns 'Bart, Lisa & Maggie'
# list([ {name: 'Bart'}, {name: 'Lisa'} ])
@RickGriff
RickGriff / pry-orm.rb
Created January 13, 2018 11:09
Bloc Rails ORM Assignment 33 - Exploring Objects with Pry
[5] pry(#<Post>):1> nesting
Nesting status:
--
0. main (Pry top level)
1. #<Post>
[6] pry(#<Post>):1> self.to_s
=> "#<Post:0x000000035f51d8>"
[7] pry(#<Post>):1> self
=> #<Post:0x000000035f51d8
id: 1,
@RickGriff
RickGriff / disemvowel_trolls.rb
Last active January 8, 2018 12:30
Codewars Challenge: Disemvowel Trolls
# Trolls are attacking your comment section!
# A common way to deal with this situation is to remove all of the vowels from the trolls' comments, neutralizing the threat.
# Your task is to write a function that takes a string and return a new string with all vowels removed.
# For example, the string "This website is for losers LOL!" would become "Ths wbst s fr lsrs LL!".
# Note: for this kata y isn't considered a vowel.
@RickGriff
RickGriff / get_middle_character.rb
Created January 7, 2018 22:48
Codewars Challenge: Get the Middle Character
# You are going to be given a word. Your job is to return the middle character of the word. If the word's length is odd, return the middle character. If the word's length is even, return the middle 2 characters.
# #Examples:
# runBF("test\0") should return "es"
# runBF("testing\0") should return "t"
# runBF("middle\0") should return "dd"
@RickGriff
RickGriff / count_most_frequent.rb
Created January 7, 2018 22:36
Codewars Challenge: Find Count of Most Frequent Item in Array
# Write a program to find count of the most frequent item of an array.
# Assume that input is array of integers.
# Ex.:
# input array: [3, -1, -1, -1, 2, 3, -1, 3, -1, 2, 4, 9, 3]
# ouptut: 5
# Most frequent number in example array is -1. It occurs 5 times in input array.
-----