Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative Advanced Code Solution #35965

Merged
merged 8 commits into from May 24, 2019
Expand Up @@ -147,6 +147,26 @@ Make sure that each time you transcode a character from binary to decimal, you r

* <a href='http://forum.freecodecamp.com/t/javascript-array-prototype-map/14294' target='_blank' rel='nofollow'>Array.prototype.map</a>

## ![:rotating_light:](https://forum.freecodecamp.com/images/emoji/emoji_one/rotating_light.png?v=3 ":rotating_light:") Alternative Advanced Code Solution:
```js
const binaryAgent = str => str.replace(/\d+./g, char => String.fromCharCode(`0b${char}`));

binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111");
```

## Code Explanation

* Find all groups of one or more digits followed by one other character
* Replace with a string created from the specified sequence of UTF-16 code units
codingcrystals marked this conversation as resolved.
Show resolved Hide resolved
* Use `0b` to lead the code unit to express that a binary integer literal is being converted.

## Relevant Links

* <a href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode' target='_blank' rel='nofollow'>String.fromCharCode()</a>
* <a href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace' target='_blank' rel='nofollow'>String.prototype.replace()</a>
* <a href='https://codegolf.stackexchange.com/questions/35096/convert-a-string-of-binary-characters-to-the-ascii-equivalents' target='_blank' rel='nofollow'>Convert a string of binary characters to the ASCII equivalents</a>
* <a href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#Numeric_literals' target='_blank' rel='nofollow'>Grammar and types/Numeric Literals</a>

## ![:clipboard:](https://forum.freecodecamp.com/images/emoji/emoji_one/clipboard.png?v=3 ":clipboard:") NOTES FOR CONTRIBUTIONS:

* ![:warning:](https://forum.freecodecamp.com/images/emoji/emoji_one/warning.png?v=3 ":warning:") **DO NOT** add solutions that are similar to any existing solutions. If you think it is **_similar but better_**, then try to merge (or replace) the existing similar solution.
Expand Down