-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalgorithm17.html
28 lines (17 loc) · 893 Bytes
/
algorithm17.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<!DOCTYPE html>
<html>
<body>
<script>
//https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/binary-agents
//Return an English translated sentence of the passed binary string.
//The binary string will be space separated.
function binaryAgent(str) {
var newStr = str.split(" ");
return newStr.map(number => String.fromCharCode(parseInt(number,2))).join("");
}
//tests
console.log(binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111"));
console.log(binaryAgent("01001001 00100000 01101100 01101111 01110110 01100101 00100000 01000110 01110010 01100101 01100101 01000011 01101111 01100100 01100101 01000011 01100001 01101101 01110000 00100001"));
</script>
</body>
</html>