Alternative Advanced Code Solution (#35965)
* Alternative Advanced Code Solution Uses .replace() instead of .split()-.join() * Update guide/english/certifications/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/binary-agents/index.md Co-Authored-By: Parth Parth <34807532+thecodingaviator@users.noreply.github.com> * Update guide/english/certifications/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/binary-agents/index.md Co-Authored-By: Parth Parth <34807532+thecodingaviator@users.noreply.github.com> * Update guide/english/certifications/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/binary-agents/index.md Co-Authored-By: Parth Parth <34807532+thecodingaviator@users.noreply.github.com> * Update guide/english/certifications/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/binary-agents/index.md Co-Authored-By: Parth Parth <34807532+thecodingaviator@users.noreply.github.com> * Update guide/english/certifications/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/binary-agents/index.md Co-Authored-By: Parth Parth <34807532+thecodingaviator@users.noreply.github.com> * Update guide/english/certifications/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/binary-agents/index.md Co-Authored-By: Randell Dawson <5313213+RandellDawson@users.noreply.github.com> * Addresses review by RandellDawson
This commit is contained in:
committed by
Parth Parth
parent
d7e0348c07
commit
c37cb92e63
@ -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>
|
* <a href='http://forum.freecodecamp.com/t/javascript-array-prototype-map/14294' target='_blank' rel='nofollow'>Array.prototype.map</a>
|
||||||
|
|
||||||
|
##  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
|
||||||
|
* 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>
|
||||||
|
|
||||||
##  NOTES FOR CONTRIBUTIONS:
|
##  NOTES FOR CONTRIBUTIONS:
|
||||||
|
|
||||||
*  **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.
|
*  **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.
|
||||||
|
Reference in New Issue
Block a user