Skip to content

Commit

Permalink
string exercises: completed
Browse files Browse the repository at this point in the history
  • Loading branch information
vinay committed Jan 9, 2024
1 parent a5801ba commit 94b3203
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
11 changes: 10 additions & 1 deletion ruby_basics/1_data_types/exercises/string_exercises.rb
Original file line number Diff line number Diff line change
@@ -1,40 +1,49 @@
def concatenate_example(string)
# use concatenation to format the result to be "Classic <string>"
"Classic " << string
"Classic " + string
end

def concatenate(string)
"Hello #{string}!"
# use concatenation to format the result to be "Hello <string>!"
end

def substrings(word)
word[0..3]
# return the first 4 letters from the word using substrings
end

def capitalize(word)
word.capitalize
# capitalize the first letter of the word
end

def uppercase(string)
string.upcase
# uppercase all letters in the string
end

def downcase(string)
string.downcase
# downcase all letters in the string
end

def empty_string(string)
string.empty?
# return true if the string is empty
end

def string_length(string)
string.length
# return the length of the string
end

def reverse(string)
string.reverse
# return the same string, with all of its characters reversed
end

def space_remover(string)
string.split.join("")
# remove all the spaces in the string using gsub
end
34 changes: 17 additions & 17 deletions ruby_basics/1_data_types/spec/strings_exercises_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,96 +16,96 @@
expect(concatenate('world')).to eq('Hello world!')
end

xit 'returns "Hello universe!"' do
it 'returns "Hello universe!"' do
expect(concatenate('universe')).to eq('Hello universe!')
end
end

describe 'substrings exercise' do

xit 'returns the first 4 letters of the word' do
it 'returns the first 4 letters of the word' do
expect(substrings('chocolate')).to eq('choc')
end
end

describe 'capitalizing exercise' do

xit 'capitalizes a word' do
it 'capitalizes a word' do
expect(capitalize('paris')).to eq('Paris')
end

xit 'only capitalizes the first word if there are multiple words' do
it 'only capitalizes the first word if there are multiple words' do
expect(capitalize('miami in the summer')).to eq('Miami in the summer')
end

xit 'leaves an already capitalized word as is' do
it 'leaves an already capitalized word as is' do
expect(capitalize('London')).to eq('London')
end
end

describe 'uppercasing exercise' do

xit 'uppercases a word' do
it 'uppercases a word' do
expect(uppercase('small')).to eq('SMALL')
end

xit 'uppercases multiple words' do
it 'uppercases multiple words' do
expect(uppercase('make me bigger')).to eq('MAKE ME BIGGER')
end
end


describe 'downcasing exercise' do

xit 'downcases a word' do
it 'downcases a word' do
expect(downcase('LARGE')).to eq('large')
end

xit 'downcases multiple words' do
it 'downcases multiple words' do
expect(downcase('MAKE ME SMALLER')).to eq('make me smaller')
end
end

describe 'empty exercise' do

xit 'returns true if string is empty' do
it 'returns true if string is empty' do
expect(empty_string('')).to eq(true)
end

xit 'returns false if string is not empty' do
it 'returns false if string is not empty' do
expect(empty_string('wow')).to eq(false)
end
end

describe 'length exercise' do

xit 'returns the length of a word' do
it 'returns the length of a word' do
expect(string_length('longitude')).to eq(9)
end

xit 'returns the length of a string with multiple words' do
it 'returns the length of a string with multiple words' do
expect(string_length('i am quite long')).to eq(15)
end
end

describe 'reverse exercise' do

xit 'reverses a word' do
it 'reverses a word' do
expect(reverse('desrever')).to eq('reversed')
end

xit 'reverses multiple words' do
it 'reverses multiple words' do
expect(reverse('dnuora kcab')).to eq('back around')
end
end

describe 'remove spaces exercise' do

xit 'removes a single space' do
it 'removes a single space' do
expect(space_remover('white space')).to eq('whitespace')
end

xit 'removes multiple spaces' do
it 'removes multiple spaces' do
expect(space_remover('many white spaces')).to eq('manywhitespaces')
end
end
Expand Down

0 comments on commit 94b3203

Please sign in to comment.