-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring0617.js
More file actions
31 lines (28 loc) · 756 Bytes
/
string0617.js
File metadata and controls
31 lines (28 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const pali = (str) => {
var regexp = /[\W_]/g;
str = str.toLowerCase().replace(regexp, '');
for (let i = 0; i < str.length / 2; i++) {
if (str[i] !== str[str.length - 1 - i]) {
return false;
}
}
return true;
};
const cezar = (str, int) => {
let result = '';
for (let i = 0; i < str.length; i++) {
let word = str[i];
if (word.match(/[a-z]/i)) {
let number = str.charCodeAt(i);
if (number >= 65 && number <= 90) {
word = String.fromCharCode(((word - 65 + int) % 26) + 65);
} else if (number >= 97 && number <= 122) {
word = String.fromCharCode(((word - 97 + int) % 26) + 97);
}
}
result += word;
}
return result;
};
let string = 'abc';
console.log(cezar(string, 3));