Skip to content

Commit 2db24ee

Browse files
author
juanantonioledesma
committed
Add "Create Phone Number" kata
1 parent ced0180 commit 2db24ee

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

6-kyu/create-phone-number.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<h1>Create Phone Number <sup><sup>6 Kyu</sup></sup></h1>
2+
3+
<sup>
4+
<a href="https://www.codewars.com/kata/525f50e3b73515a6db000b83">
5+
<strong>LINK TO THE KATA</strong>
6+
</a> - <code>ARRAYS</code> <code>STRINGS</code> <code>REGULAR EXPRESSIONS</code> <code>ALGORITHMS</code>
7+
</sup>
8+
9+
## Description
10+
11+
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.
12+
13+
**Example**
14+
15+
```javascript
16+
createPhoneNumber([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]) // => returns "(123) 456-7890"
17+
```
18+
19+
The returned format must be correct in order to complete this challenge.
20+
21+
Don't forget the space after the closing parentheses!
22+
23+
## Solution
24+
25+
```javascript
26+
const createPhoneNumber = numbers => {
27+
const stringNumbers = numbers.join('')
28+
29+
const prefix = stringNumbers.substr(0, 3)
30+
const firstGroup = stringNumbers.substr(3, 3)
31+
const lastGroup = stringNumbers.substr(6, 4)
32+
33+
return `(${prefix}) ${firstGroup}-${lastGroup}`
34+
}
35+
```

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ JavaScript katas on Codewars are programming challenges that help you improve yo
3131
- **[Convert string to camel case](./6-kyu/convert-string-to-camel-case.md)**
3232
- **[Count the smiley faces!](./6-kyu/count-the-smiley-faces.md)**
3333
- **[Counting Duplicates](./6-kyu/counting-duplicates.md)**
34+
- **[Create Phone Number](./6-kyu/create-phone-number.md)**
3435
- **[Decode the Morse code](./6-kyu/decode-the-morse-code.md)**
3536
- **[Delete occurrences of an element if it occurs more than n times](./6-kyu/delete-occurrences-of-an-element-if-it-occurs-more-than-n-times.md)**
3637
- **[Detect Pangram](./6-kyu/detect-pangram.md)**

0 commit comments

Comments
 (0)