Skip to content

Commit 2af5628

Browse files
committed
Complete binary agents algorithm
1 parent a2c697b commit 2af5628

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export function binaryAgents(str) {
2+
let binaryArray = str.split(" ");
3+
let stringArray = binaryArray.map(val => String.fromCharCode(parseInt(val, 2)));
4+
return stringArray.join("");
5+
}

src/fcc-intermediate-algorithms/fcc-intermediate-algorithms.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ From the Freecodecamp Javascript Certification Intermediate Algorithms module
1919
- [Sum All Primes](#sum-all-primes)
2020
- [Smallest Common Multiple](#smallest-common-multiple)
2121
- [Drop It](#drop-it)
22+
- [Binary Agents](#binary-agents)
2223

2324
#### Sum All Numbers In a Range
2425

@@ -365,3 +366,17 @@ export function steamrollArray(arr) {
365366
}, []);
366367
}
367368
```
369+
370+
#### Binary Agents
371+
372+
Return an English translated sentence of the passed binary string.
373+
374+
The binary string will be space separated.
375+
376+
```javascript
377+
export function binaryAgents(str) {
378+
let binaryArray = str.split(" ");
379+
let stringArray = binaryArray.map(val => String.fromCharCode(parseInt(val, 2)));
380+
return stringArray.join("");
381+
}
382+
```
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { binaryAgents } from "../../src/fcc-intermediate-algorithms/binary_agents";
2+
3+
test('should convert binary to english', () => {
4+
const binary = "01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111";
5+
expect(binaryAgents(binary)).toBe("Aren't bonfires fun!?");
6+
});

0 commit comments

Comments
 (0)