Example A — Fixed-length binary (5-bit) for lowercase letters and space
The above solution uses a "prefix symbol" approach. However, you can be creative. Here are three other encoding ideas that will also receive full credit:
The code examples provide a fully functional solution. However, the very nature of the assignment is to create your own unique scheme. You must modify the encoding map to make it your own. The provided code is a complete template you can customize.
Decide on a pattern or rule that you will use to encode your message. A common pattern is to shift each letter by a certain number of places in the alphabet. For example, in a Caesar Cipher, if you shift by 3, 'a' becomes 'd', 'b' becomes 'e', and so on.
: Use a for loop to look at each individual character of the string one by one.
// Encode function: converts plain text to custom encoding function encode(message) var encoded = ""; for (var i = 0; i < message.length; i++) var char = message[i].toLowerCase(); // Handle uppercase if (encodingMap[char] !== undefined) encoded += encodingMap[char]; else // If character is not in map, keep it as is encoded += char;