-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy path21-encode.js
More file actions
22 lines (19 loc) · 584 Bytes
/
Copy path21-encode.js
File metadata and controls
22 lines (19 loc) · 584 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// node 21-encode.js "abcdefg"
// Get the input text from the command line arguments
const inputText = process.argv[2];
// Shift every character one character to the left
let outputText = "";
for (let i = 0; i < inputText.length; i++) {
const char = inputText.charAt(i);
if (char === "a") {
// Handle special case for 'a'
outputText += "z";
} else if (char === "A") {
// Handle special case for 'A'
outputText += "Z";
} else {
outputText += String.fromCharCode(char.charCodeAt(0) - 1);
}
}
// Output the result in the console
console.log(outputText);