Skip to content

Instantly share code, notes, and snippets.

@McLarenCollege
Last active August 8, 2022 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save McLarenCollege/dc70a160e60965ceb3baad284a25c49c to your computer and use it in GitHub Desktop.
Save McLarenCollege/dc70a160e60965ceb3baad284a25c49c to your computer and use it in GitHub Desktop.
Encode Message

Write a function that encodes a given string by constructing a new string adding every third character.

Encoding process begins with the first character and every third character is added to the encoded message till we reach the end of the string. The encoding process then starts with the second character and we jump every two characters till we reach the end of the string. Then we start a similar process starting with the third character.

Please refer to the image to understand the encoding process.

https://raw.githubusercontent.com/McLarenCollege/public_images/main/encode.jpg

CODE TEMPLATE


function encode(str){
// write your code here
}
let msg = 'ICE CREAM';
console.log(encode(msg)); // "I ECCAERM"
console.log(encode("Today is Monday"));// "TaiMdoysoad  ny"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment