NRZI code (Non-Return-to-Zero, Inverted) is one of the methods of linear coding. It has two signal levels and is used to transmit bit sequences containing only 0 and 1. NRZI is used, for example, in optical cables, where only two signal states are consistently recognized, light and dark.
When transmitting a logical zero to the input of the coding device, the potential set at the previous clock cycle is transmitted (that is, the state of the potential does not change), and when transmitting a logical unit, the potential inverts.
Implement and export as default a function that accepts a string as a graphical representation of a linear signal and returns a binary code string. Carefully study the examples.
const signal1 = '_|¯|____|¯|__|¯¯¯'; nrzi(signal1); // '011000110100' const signal2 = '|¯|___|¯¯¯¯¯|___|¯|_|¯'; nrzi(signal2); // '110010000100111' const signal3 = '¯|___|¯¯¯¯¯|___|¯|_|¯'; nrzi(signal3); // '010010000100111' const signal4 = ''; nrzi(signal4); // '' const signal5 = '|'; nrzi(signal5); // ''
|char indicates the signal switching and means that the signal level in the next clock cycle will be changed to the opposite compared to the previous one
For full access to the challenge you need a professional subscription.
A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.