Ruby solution
require "minitest/autorun" class WordTrimmer def initialize word @word = word end def trim @word.length <= 2 ? @word : @word[1..-2] end end class WordTrimmerTest < MiniTest::Test def test_removing_first_and_last_letter assert_equal "aspe", WordTrimmer.new("kasper").trim end def test_ignoring_two_letter_word assert_equal "hi", WordTrimmer.new("hi").trim end def test_ignoring_one_letter_word assert_equal "I", WordTrimmer.new("I").trim end end
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Ruby solution