-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
replace-with-alphabet-position.js
72 lines (63 loc) · 1.72 KB
/
replace-with-alphabet-position.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
function alphabetPosition(text) {
const numbers = [];
for (let i = 0; i < text.length; i++) {
const letter = text[i];
const number = letter.toUpperCase().charCodeAt(0) - 64;
if (number >= 1 && number <= 26) {
numbers.push(number);
}
}
return numbers.join(' ');
}
function alphabetPosition(text) {
return text.replace(/[^a-zA-Z]/g, '').split('').map(letter => {
return letter.toUpperCase().charCodeAt(0) - 64;
}).join(' ');
}
function alphabetPosition(text) {
return text.toUpperCase().replace(/[^A-Z]/g, '').split('').map(letter => {
return letter.charCodeAt(0) - 64;
}).join(' ');
}
function alphabetPosition(text) {
return Array.prototype.map.call(text
.toUpperCase()
.replace(/[^A-Z]/g, ''), letter => {
return letter.charCodeAt(0) - 64;
}).join(' ');
}
// alca
function alphabetPosition(text) {
return text
.toUpperCase()
.split('')
.map(n => n.charCodeAt(0) - 64)
.filter(n => n > 0 && n <= 26)
.join(' ');
}
//alca
function alphabetPosition(text) {
return text
.toUpperCase()
.replace(/[^A-Z]/g, '')
.split('')
.map(n => n.charCodeAt(0) - 64)
.join(' ')
}
function alphabetPosition(text) {
let numbers = '';
for (let i = 0; i < text.length; i++) {
const letter = text[i];
const number = letter.toUpperCase().charCodeAt(0) - 64;
if (number >= 1 && number <= 26) {
numbers += number + ' ';
}
}
return numbers.trim();
}
console.log(
alphabetPosition("The sunset sets at twelve o' clock."),
"20 8 5 19 21 14 19 5 20 19 5 20 19 1 20 20 23 5 12 22 5 15 3 12 15 3 11");
console.log(
alphabetPosition("The narwhal bacons at midnight."),
"20 8 5 14 1 18 23 8 1 12 2 1 3 15 14 19 1 20 13 9 4 14 9 7 8 20");