-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatements.js
More file actions
116 lines (108 loc) · 3.45 KB
/
statements.js
File metadata and controls
116 lines (108 loc) · 3.45 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
var texto = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin ultricies massa sit amet tellus fringilla, eu placerat lacus sodales. Suspendisse potenti. Cras placerat turpis nec lectus bibendum fermentum. Maecenas molestie erat eu neque pulvinar, eu pellentesque felis pretium. Suspendisse potenti. Suspendisse turpis ipsum, aliquet sit amet vehicula ut, sollicitudin id elit. Cras laoreet faucibus turpis.";
var toHackerCase = function (text) {
var hackerTextArray = [];
for (var i = 0; i < texto.length; i++) {
if (text.charAt(i) === "a") {
hackerTextArray.push(4);
continue;
}
if (text.charAt(i) === "e") {
hackerTextArray.push(3);
continue;
}
if (text.charAt(i) === "i") {
hackerTextArray.push(1);
continue;
}
if (text.charAt(i) === "o") {
hackerTextArray.push(0);
continue;
}
if (text.charAt(i) === "s") {
hackerTextArray.push(5);
continue;
}
if (text.charAt(i) === "t") {
hackerTextArray.push(7);
continue;
} hackerTextArray.push(text.charAt(i));
}
return hackerTextArray.join("");
};
console.log(toHackerCase(texto));
var toHackerCase = function (text) {
var hackerTextArray = [];
for (var i = 0; i < texto.length; i++) {
switch(text.charAt(i)) {
case "a":
hackerTextArray.push(4);
break;
case "e":
hackerTextArray.push(3);
break;
case "i":
hackerTextArray.push(1);
break;
case "o":
hackerTextArray.push(0);
break;
case "s":
hackerTextArray.push(5);
break;
case "t":
hackerTextArray.push(7);
break;
default:
hackerTextArray.push(text.charAt(i));
}
}
return hackerTextArray.join("");
};
console.log(toHackerCase(texto));
var toHackerCase = function (text) {
if (!text) throw new HackerTextError("Texto inválido.");
if (typeof text !== "string") throw new HackerTextError("Tipo inválido.");
var hackerTextArray = [];
var i = 0;
while(i < text.length) {
switch(text.charAt(i)) {
case "a":
hackerTextArray.push(4);
break;
case "e":
hackerTextArray.push(3);
break;
case "i":
hackerTextArray.push(1);
break;
case "o":
hackerTextArray.push(0);
break;
case "s":
hackerTextArray.push(5);
break;
case "t":
hackerTextArray.push(7);
break;
default:
hackerTextArray.push(text.charAt(i));
}
i++;
}
return hackerTextArray.join("");
};
console.log(toHackerCase(texto));
var HackerTextError = function (message) {
this.message = message;
this.name = "HackerTextError";
}
try {
console.log(toHackerCase());
} catch (e) {
console.log("Erro: " + e.message);
}
try {
console.log(toHackerCase(10));
} catch (e) {
console.log("Erro: " + e.message);
}