Skip to content

Commit b9b7278

Browse files
author
juanantonioledesma
committed
Add "Data Reverse" kata
1 parent 7322583 commit b9b7278

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

6-kyu/data-reverse.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<h1>Data Reverse <sup><sup>6 Kyu</sup></sup></h1>
2+
3+
<sup>
4+
<a href="https://www.codewars.com/kata/569d488d61b812a0f7000015">
5+
<strong>LINK TO THE KATA</strong>
6+
</a> - <code>ARRAYS</code> <code>FUNDAMENTALS</code>
7+
</sup>
8+
9+
## Description
10+
11+
A stream of data is received and needs to be reversed.
12+
13+
Each segment is 8 bits long, meaning the order of these segments needs to be reversed, for example:
14+
15+
```
16+
11111111 00000000 00001111 10101010
17+
(byte1) (byte2) (byte3) (byte4)
18+
```
19+
20+
should become:
21+
22+
```
23+
10101010 00001111 00000000 11111111
24+
(byte4) (byte3) (byte2) (byte1)
25+
```
26+
27+
The total number of bits will always be a multiple of 8.
28+
29+
The data is given in an array as such:
30+
31+
```
32+
[1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,1,0,1,0,1,0]
33+
```
34+
35+
## Solution
36+
37+
```javascript
38+
const dataReverse = data => {
39+
if (data.length === 0) return []
40+
41+
return data
42+
.join('')
43+
.match(/\d{8}/g)
44+
.reverse()
45+
.join('')
46+
.split('')
47+
.map(character => Number(character))
48+
}
49+
```

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ JavaScript katas on Codewars are programming challenges that help you improve yo
5050
- **[Count the smiley faces!](./6-kyu/count-the-smiley-faces.md)**<br><sup>`REGULAR EXPRESSIONS` `FUNDAMENTALS`</sup>
5151
- **[Counting Duplicates](./6-kyu/counting-duplicates.md)**<br><sup>`STRINGS` `FUNDAMENTALS`</sup>
5252
- **[Create Phone Number](./6-kyu/create-phone-number.md)**<br><sup>`ARRAYS` `STRINGS` `REGULAR EXPRESSIONS` `ALGORITHMS`</sup>
53+
- **[Data Reverse](./6-kyu/data-reverse.md)**<br><sup>`ARRAYS` `FUNDAMENTALS`</sup>
5354
- **[Decode the Morse code](./6-kyu/decode-the-morse-code.md)**<br><sup>`ALGORITHMS`</sup>
5455
- **[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)**<br><sup>`LISTS` `FUNDAMENTALS`</sup>
5556
- **[Detect Pangram](./6-kyu/detect-pangram.md)**<br><sup>`STRINGS` `DATA STRUCTURES` `FUNDAMENTALS`</sup>

0 commit comments

Comments
 (0)