-
-
Save YKalashnikov/fd299571fee403b6990d9c1fe18bd2ff to your computer and use it in GitHub Desktop.
# Write a method that converts an array of ten integers into a phone number in the format "(123) 456-7890".
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
WHAT'S WRONG WITH THE CODE? | |
# Write a method that converts an array of ten integers into a phone number in the format "(123) 456-7890". | |
def to_phone_number(arr) | |
chunk_one = arr[0..2].join | |
chunk_two = arr[3..5].join | |
chunk_three = arr[6..9].join | |
"(" + chunk_one + ")" + " " + chunk_two + "-" + chunk_three | |
end | |
puts (to_phone_number("1234567890")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment