2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
id: a8d97bd4c764e91f9d2bda01
|
2021-01-12 08:18:51 -08:00
|
|
|
title: 翻译二进制字符串
|
2018-10-10 18:03:03 -04:00
|
|
|
challengeType: 5
|
2020-09-07 16:10:29 +08:00
|
|
|
forumTopicId: 14273
|
2021-01-13 03:31:00 +01:00
|
|
|
dashedName: binary-agents
|
2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --description--
|
2020-09-07 16:10:29 +08:00
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
请实现一个函数,把传入的二进制字符串转换成英文句子。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
二进制字符串会以空格分隔。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --hints--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`binaryAgent('01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111')` 应返回 "Aren't bonfires fun!?"。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
```js
|
2020-12-16 00:37:30 -07:00
|
|
|
assert.deepEqual(
|
|
|
|
binaryAgent(
|
|
|
|
'01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111'
|
|
|
|
),
|
|
|
|
"Aren't bonfires fun!?"
|
|
|
|
);
|
2018-10-10 18:03:03 -04:00
|
|
|
```
|
|
|
|
|
2021-01-12 08:18:51 -08:00
|
|
|
`binaryAgent('01001001 00100000 01101100 01101111 01110110 01100101 00100000 01000110 01110010 01100101 01100101 01000011 01101111 01100100 01100101 01000011 01100001 01101101 01110000 00100001')` 应返回 "I love FreeCodeCamp!"。
|
2020-09-07 16:10:29 +08:00
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
```js
|
2020-12-16 00:37:30 -07:00
|
|
|
assert.deepEqual(
|
|
|
|
binaryAgent(
|
|
|
|
'01001001 00100000 01101100 01101111 01110110 01100101 00100000 01000110 01110010 01100101 01100101 01000011 01101111 01100100 01100101 01000011 01100001 01101101 01110000 00100001'
|
|
|
|
),
|
|
|
|
'I love FreeCodeCamp!'
|
|
|
|
);
|
2018-10-10 18:03:03 -04:00
|
|
|
```
|
2020-08-13 17:24:35 +02:00
|
|
|
|
2021-01-13 03:31:00 +01:00
|
|
|
# --seed--
|
|
|
|
|
|
|
|
## --seed-contents--
|
|
|
|
|
|
|
|
```js
|
|
|
|
function binaryAgent(str) {
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111");
|
|
|
|
```
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --solutions--
|
|
|
|
|
2021-01-13 03:31:00 +01:00
|
|
|
```js
|
|
|
|
function binaryAgent(str) {
|
|
|
|
return str.split(' ').map(function(s) { return parseInt(s, 2); }).map(function(b) { return String.fromCharCode(b);}).join('');
|
|
|
|
}
|
|
|
|
```
|