cesar ciupher js
function caesarCipher(str, shift) {
const alphabetArr = "abcdefghijklmnopqrstuvwxyz".split("");
let res = "";
for (let i = 0; i < str.length; i++) {
const char = str[i];
const idx = alphabetArr.indexOf(char);
// if it is not a letter, don`t shift it
if (idx === -1) {
res += char;
continue;
}
// only 26 letters in alphabet, if > 26 it wraps around
const encodedIdx = (idx + shift) % 26;
res += alphabetArr[encodedIdx];
}
return res;
}
Also in JavaScript:
- javascript access to xmlhttprequest at from origin 'null' has been blocked by cors policy
- javascrpt refresh page
- jquery number format thousand k
- how to add field to object in js
- jquery siblings
- vue router implementation
- dynamic loaded content can't find library jqury
- js oneline foreach
- how to Write a program that simulates a coin toss using random method of Javascript Math class
- javascript lerp
- jquery on scroll down
- create array javascript fill
- how to loop object javascript
- codemirror get value
- jqgrid beforeShowForm
- How to change htm h1 from nodejs
- javascript randint
- document delete element
- express get full url
- kendo js add one day to a date
- how to log something in the console. javascript
- nexusjs file upload
- javascript calculate age
- get last item in map javascript