Setup
Implement a function that accepts an array of 10 integers. Have the function return those numbers as a String in the form of a phone number. Please use the following format for the phone number: (XXX) XXX-XXXX
. Integers in the array will be no larger than 9.
Example
createPhoneNumber([1, 2, 3, 4, 5, 6, 7, 8, 9, 0])
// should return (123) 456-7890
Tests
createPhoneNumber([1, 2, 3, 4, 5, 6, 7, 8, 9, 0])
createPhoneNumber([1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
createPhoneNumber([1, 2, 3, 4, 5, 6, 7, 8, 9, 0])
Good luck!
This challenge comes from xDranik on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (10)
Elixir
I'm sure there's a much simpler way, though.
Haskell
Ruby
Dart - I'm all about being explicit and ensuring the expected result is what I want rather than trying to be creative and smart.
In Python:
JAVA
JavaScript