Hello @ankurchaulagain,
Nice it works - I used the ASCII method myself but only because if the information is there already I tend to like to use it rather than recreate it somewhere else (but not always, all depends on readablity, optimisation and other factors).
Anyhow here are some niggle possible pointers and suggestions.
syntax, extra semi-colon [;] are being used, it doesn’t break it, but not usually done.
if(){
//...
}
else{
//...
}; //this one
//and
return ... ;;
ease of reading, the if statement using a oneline and then multiline for the else:
if(){}
else{
}
//multiline for both
if(){
}
else{
}
Manipulation of str, one at top and another at bottom separated by function shiftLetters, putting them together may help when issues arise and you need to debug.
Also the return using a oneliner, but also manipulating str above with split - why not combine them
str = ...
function (){
//many lines
}
return str....
//put them together
function (){
//many lines
}
str = //...
return str....
//or oneliner them all
function (){
//many lines
}
return str.split('').map ...
//for readablity possibly split up the oneliner notation:
return str
.split("")
.map(a => shiftLetters(a))
.join("")
;
//but may think str is getting return but is being processed below
within shiftLetters function, possibly use += and -=
letterIndex = letterIndex - 13;
letterIndex = letterIndex + 26;
//+= and -=
letterIndex -= 13;
letterIndex += 26;
Naming of variable and function, alphabets and shiftLetters they both end with s meaning plural, more than one.
alphabets variable is only one alphabet but consists of multiple letters, suggest using var alphabet instead of var alphabets.
shiftLetters function is only shifting one letter and not multiple letters,s uggest using function shiftLetter instead of function shiftLetters.
May consider using === instead of == in the comparision:
Anyhow nice work, these are just some niggly things you might want to consider.
Happy coding