Last active
January 10, 2020 07:03
-
-
Save omegahm/21077b220e7bad077909ca698c80c20e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rspec' | |
RSpec.describe do | |
%w(spongebobify minisponge).each do |method| | |
context "##{method}" do | |
it 'fox' do | |
expect(send(method, 'fox')).to eq('fOx') | |
expect(send(method, 'FOX')).to eq('fOx') | |
end | |
it 'i' do | |
expect(send(method, 'i')).to eq('I') | |
expect(send(method, 'I')).to eq('I') | |
end | |
it 'i love pie' do | |
expect(send(method, 'i love pie')).to eq('I LoVe piE') | |
end | |
it 'brown' do | |
expect(send(method, 'brown')).to eq('bRoWn') | |
expect(send(method, 'BROWN')).to eq('bRoWn') | |
end | |
it 'lazy' do | |
expect(send(method, 'lazy')).to eq('LaZy') | |
end | |
it 'billiards' do | |
expect(send(method, 'billiards')).to eq('biLLiArDs') | |
end | |
it 'quick' do | |
expect(send(method, 'quick')).to eq('qUiCk') | |
end | |
it 'spongebobifies' do | |
expect(send(method, 'the quick brown fox jumps over the lazy dog')).to eq('tHe qUiCk bRoWn fOx jUmPs oVeR tHe LaZy dOg') | |
end | |
end | |
end | |
end | |
def spongebobify(str) | |
str.downcase.split(' ').map do |word| | |
next 'I' if 'i' == word | |
lowercase = true | |
word.chars.map do |char| | |
case char | |
when 'l' | |
'L' | |
when 'i' | |
lowercase = false | |
'i' | |
else | |
lowercase = !lowercase | |
lowercase ? char.upcase : char | |
end | |
end.join | |
end.join(' ') | |
end | |
def minisponge(s) | |
# 103 chars | |
s.downcase.split.map{|w|l=!p&&w==?i??I:w.chars.map{|c|c[?l]??L:c[?i]?l=!p&&c:(l=!l)?c:c.upcase}*''}*' ' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
97 char version
Doesn't work for
"quick"
as it transforms it to"qUicK"
instead of"qUiCk"
.