File tree Expand file tree Collapse file tree 3 files changed +26
-0
lines changed
src/fcc-intermediate-algorithms
tests/fcc-intermediate-algorithms Expand file tree Collapse file tree 3 files changed +26
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ From the Freecodecamp Javascript Certification Intermediate Algorithms module
19
19
- [ Sum All Primes] ( #sum-all-primes )
20
20
- [ Smallest Common Multiple] ( #smallest-common-multiple )
21
21
- [ Drop It] ( #drop-it )
22
+ - [ Binary Agents] ( #binary-agents )
22
23
23
24
#### Sum All Numbers In a Range
24
25
@@ -365,3 +366,17 @@ export function steamrollArray(arr) {
365
366
}, []);
366
367
}
367
368
```
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
+ ```
Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments