Encoding the Input Data
Read Input and Encode Characters with Assigned Codes
Encode each character using the previously assigned codes.
Output the Resulting Bit Sequence
The output will be a string of bits representing the encoded text.
Here's the encoding code:
1// JavaScript code for encoding
2function encode(inputText, codes) {
3 return inputText.split('').map(c => codes[c]).join('');
4}