Alphabetic Shift

Description


Given a string, replace each its character by the next one in the English alphabet (z would be replaced by a).

Example

For inputString = "crazy", the output should be alphabeticShift(inputString) = "dsbaz".

Input/Output

  • [execution time limit] 4 seconds (js)

  • **[input] string inputString **

Non-empty string consisting of lowercase English characters.

Guaranteed constraints: 1 ≤ inputString.length ≤ 1000.

  • [output] string

The result string after replacing all of its characters.

[JavaScript (ES6)] Syntax Tips

1
2
3
4
5
6
// Prints help message to the console
// Returns a string
function helloWorld(name) {
    console.log("This prints to the console when you Run Tests");
    return "Hello, " + name;
}

Solution


1
2
3
function alphabeticShift(inputString) {
    return inputString.split('').map(c=>c.charCodeAt(0)=== 122?'a':String.fromCharCode(c.charCodeAt(0)+1)).join('');
}