Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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)