Introduction

Hello! Are you ready for an exciting voyage into the wonderful realm of strings and data structures? Today, we will assist Alice, an aspiring cryptographer, with an intriguing string manipulation task. She loves playing with strings and has come up with a unique string encoding scheme. I assure you, this will be an enlightening journey that will stretch your programming muscles. Let's get started!

Task Statement
Solution Building: Step 1 - Mapping each character to the next alphabetical character

Our first step involves mapping each character of the input string to the next alphabetical character. For this, we define nextString as an empty string, storing the shift operation result. We then iterate over each character of the input string. If a character is not z, we replace it with the next alphabetical character. If it is z, we replace it with a.

Here's the updated function in JavaScript:

JavaScript
function characterFrequencyEncoding(word) {
    let nextString = '';
    for (let i = 0; i < word.length; i++) {
        let letter = word[i];
        if (letter === 'z') {
            nextString += 'a';
        } else {
            nextString += String.fromCharCode(letter.charCodeAt(0) + 1);
        }
    }
    return nextString;
}
Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal