Skip to content

Commit 79b07a2

Browse files
Add "Tail Swap" kata
1 parent 9655ce6 commit 79b07a2

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

7-kyu/tail-swap.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<h1>Tail Swap <sup><sup>7 Kyu</sup></sup></h1>
2+
3+
<sup>
4+
<a href="https://www.codewars.com/kata/5868812b15f0057e05000001">
5+
<strong>LINK TO THE KATA</strong>
6+
</a> - <code>FUNDAMENTALS</code>
7+
</sup>
8+
9+
## Description
10+
11+
You'll be given a list of two strings, and each will contain exactly one colon (`":"`) in the middle (but not at beginning or end). The length of the strings, before and after the colon, are random.
12+
13+
Your job is to return a list of two strings (in the same order as the original list), but with the characters after each colon swapped.
14+
15+
**Examples**
16+
17+
```
18+
["abc:123", "cde:456"] --> ["abc:456", "cde:123"]
19+
["a:12345", "777:xyz"] --> ["a:xyz", "777:12345"]
20+
```
21+
22+
## Solution
23+
24+
```javascript
25+
const tailSwap = arr => {
26+
const pair1 = arr[0].split(':')
27+
const pair2 = arr[1].split(':')
28+
29+
return [`${pair1[0]}:${pair2[1]}`, `${pair2[0]}:${pair1[1]}`]
30+
}ddBinary = (a, b) => (a + b).toString(2)
31+
```

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ JavaScript katas on Codewars are programming challenges that help you improve yo
218218
- **[Sum of odd numbers](./7-kyu/sum-of-odd-numbers.md)**<br><sup>`ARRAYS` `LISTS` `MATHEMATICS` `FUNDAMENTALS`</sup>
219219
- **[Sum of the first nth term of Series](./7-kyu/sum-of-the-first-nth-term-of-series.md)**<br><sup>`FUNDAMENTALS`</sup>
220220
- **[Sum of two lowest positive integers](./7-kyu/sum-of-two-lowest-positive-integers.md)**<br><sup>`ARRAYS` `FUNDAMENTALS`</sup>
221+
- **[Tail Swap](./7-kyu/tail-swap.md)**<br><sup>`FUNDAMENTALS`</sup>
221222
- **[Testing 1-2-3](./7-kyu/testing-1-2-3.md)**<br><sup>`ARRAYS` `FUNDAMENTALS`</sup>
222223
- **[The highest profit wins!](./7-kyu/the-highest-profit-wins.md)**<br><sup>`LISTS` `ARRAYS` `FUNDAMENTALS`</sup>
223224
- **[The Office I - Outed](./7-kyu/the-office-i-outed.md)**<br><sup>`FUNDAMENTALS` `ARRAYS`</sup>

0 commit comments

Comments
 (0)