Skip to content

Commit ce0facb

Browse files
author
juanantonioledesma
committed
Add "Remove First and Last Character Part Two" kata
1 parent cf523a2 commit ce0facb

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<h1>Remove First and Last Character Part Two <sup><sup>8 Kyu</sup></sup></h1>
2+
3+
<sup>
4+
<a href="https://www.codewars.com/kata/570597e258b58f6edc00230d">
5+
<strong>LINK TO THE KATA</strong>
6+
</a> - <code>FUNDAMENTALS</code> <code>ARRAYS</code> <code>STRINGS</code>
7+
</sup>
8+
9+
## Description
10+
11+
You are given a string containing a sequence of character sequences separated by commas.
12+
13+
Write a function which returns a new string containing the same character sequences except the first and the last ones but this time separated by spaces.
14+
15+
If the input string is empty or the removal of the first and last items would cause the resulting string to be empty, return an empty value (represented as a generic value NULL in the examples below).
16+
17+
**Examples**
18+
19+
```
20+
"1,2,3" => "2"
21+
"1,2,3,4" => "2 3"
22+
"1,2,3,4,5" => "2 3 4"
23+
24+
"" => NULL
25+
"1" => NULL
26+
"1,2" => NULL
27+
```
28+
29+
## Solution
30+
31+
```javascript
32+
const array = arr => {
33+
const strArr = arr.split(',')
34+
35+
if (strArr.length <= 2) return null
36+
37+
return strArr.slice(1, strArr.length - 1).join(' ')
38+
}
39+
```

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,5 @@ JavaScript katas on Codewars are programming challenges that help you improve yo
7777
- **[Object Oriented Piracy](./8-kyu/object-oriented-piracy.md)**
7878
- **[Opposites Attract](./8-kyu/opposites-attract.md)**
7979
- **[Power](./8-kyu/power.md)**
80+
- **[Remove First and Last Character Part Two](./8-kyu/remove-first-and-last-character-part-two.md)**
8081
- **[Simple Comparison?](./8-kyu/simple-comparison.md)**

0 commit comments

Comments
 (0)