Challenge 39 – Format my Phone Number
Challenge #39 involved creating a function to format a telephone number.
Specifically, write a function that accepts an array of 10 integers (between 0 and 9), that returns a string of those numbers in the form of a phone number.
For instance in C#,
- Come up with the correct code format an array of integers into a correctly formatted 10 digit telephone number (123)456-7890 no spaces.
- Make the function as small (based on total number of characters) as possible and have it perform correctly.
- Any programming language may be employed.
The following is a good response as submitted by Matt Kent.
Other good response
Winner (our of approximately 25 respondents)
Thanks to everybody for your responses to SCS Coding Challenge #39!!!
Congratulations to Matt Kent for his fine effort to come up with a workable algorithm.
|Name||Prize Winner||Good Answer|
Monthly Programming Tidbits
You don’t always need an “else”!
If shape is null, we throw an exception and the rest of the method will not be executed. So, there is really no need to add that “else” block, which increases the indentation of the code. Here is a cleaner way to write this code:
Note that the rest of the code after the “if” statement is not indented.
Coding Challenge #40
Please stay tuned, SCS Coding Challenge #40 will be published early next week. Details will follow. The winner will be awarded based upon the best approach.
 Codewars – 6ku challenge – www.codewars.com