Ruby solution
require "minitest/autorun" class PhoneNumberFormatter def initialize digits @digits = digits end def format "(#{area_code}) #{central_office_code}-#{line_number}" end private def area_code @digits[0..2].join end def central_office_code @digits[3..5].join end def line_number @digits[6..9].join end end class PhoneNumberFormatterTest < MiniTest::Test def test_formatted_phone_number output = PhoneNumberFormatter.new([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]).format assert_equal "(123) 456-7890", output 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