freeCodeCamp/curriculum/challenges/russian/02-javascript-algorithms-an.../intermediate-algorithm-scri.../binary-agents.russian.md

2.4 KiB
Raw Blame History

id title isRequired challengeType forumTopicId localeTitle
a8d97bd4c764e91f9d2bda01 Binary Agents true 5 14273 Двоичные агенты

Description

Верните английское переведенное предложение прошедшей двоичной строки. Бинарная строка будет разделена пробелом. Не забудьте использовать Read-Search-Ask, если вы застряли. Попробуйте подключить программу. Напишите свой собственный код.

Instructions

Tests

tests:
  - text: <code>binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111")</code> should return "Aren&#39;t bonfires fun!?"
    testString: 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!?");
  - text: <code>binaryAgent("01001001 00100000 01101100 01101111 01110110 01100101 00100000 01000110 01110010 01100101 01100101 01000011 01101111 01100100 01100101 01000011 01100001 01101101 01110000 00100001")</code> should return "I love FreeCodeCamp!"
    testString: 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!");

Challenge Seed

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");

Solution

function binaryAgent(str) {
  return str.split(' ').map(function(s) { return parseInt(s, 2); }).map(function(b) { return String.fromCharCode(b);}).join('');
}