How to solve the Create Phone Number kata from CodeWars?

How to solve the Create Phone Number kata from CodeWars?

I usually use CodeWars to improve my problem solving skills. I got this challenge a few days back.


This is a beginner level of programming, good for people who are learning to code.

For me, the reason for doing this kind of exercises is to keep my logic problem solving skills afresh. I normally work on different kinds of tasks that doesn't involve logic on a daily basis. For instance, things like modifying part of a layout in CSS or modifying codes to cover a change in xpath in an automation project.

Moreover, solving these types of problems are also interesting, particularly when they are neither too easy nor too difficult.

As usual, there are different ways of doing this:

  • Only via concatenation
  • Divide into three parts and loop
  • Parse the text according to a format

I use the easiest example for this task.

I've written it in C# as I've recently been working on a Web Automation project using C# and NUnit.

This is my solution:


Once done, I usually glance at the top solutions, which provides an excellent opportunity of learning different ways of achieving the same result. This helps me improve my deduction, logic and programming skills.