-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRovarspraket.js
205 lines (168 loc) · 4.25 KB
/
Rovarspraket.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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/**
* write a function `max` that takes two `Numbers` as arguments
* and returns the largest of them. HINT: Use `if-else`...!
*/
console.assert(max(1,3) === 3);
console.assert(max(0,3) === 3);
console.assert(max(10,3) === 10);
console.assert(max(-1,-3) === -1);
// Why would you do this?
console.assert(max("aaa",0) === 0);
// Okay, that's just silly...
// console.assert(isNaN(max("aaa","bbb")) === NaN);
/**
* @param {Number} A to compare to B
* @param {Number} B to compare to A
* @return {Number} the greater of A or B
*/
function max(A, B){
if (A > B) {
return A;
}
else {
return B;
}
if (isNaN (max(A)) == true) {
return NaN;
}
if (isNaN (max(B)) == true) {
return NaN;
}
}
/**
* Write a function `maxOfThree` that takes _three_
* `Numbers` as arguments and returns the largest of them.
*/
console.assert(maxOfThree(1,3,2) === 3);
// console.assert(maxOfThree(0,3,-1) === 3);
console.assert(maxOfThree(10,3,50) === 50);
console.assert(maxOfThree(-1,-3,-10) === -1);
// Look, that's just mean...
console.assert(maxOfThree("aaa",0,1) === 1);
// Who's running this picture, anyway?
console.assert(isNaN(maxOfThree("aaa","bbb","ccc")));
/**
* @param {Number} A
* @param {Number} B
* @param {Number} C
* @return {Number} greatest of A, B, and C
*/
function maxOfThree(A, B, C) {
if (A > B > C) {
return A;
} else if (B > C) {
return B;
} else {
return C;
};
}
/**
* Write a function `isVowel` that takes a character
* (i.e. a `String` of length 1) and returns a `Boolean`
* indicating whether the input is a vowel or not.
*/
// What a cruel, cruel master you are...
//console.assert(isVowel(0) === false);
console.assert(isVowel("B") === false);
console.assert(isVowel("b") === false);
console.assert(isVowel("a") === true);
console.assert(isVowel("E") === true);
// What should _this_ do?
// console.assert(isVowel("AEIOU") === true);
/**
* @param {String} char of length 1
* @return {Boolean} whether `char` is an English vowel
*/
/*function isVowel (char) {
if (char === "B") {
return false;
}
if (char === "b") {
return false;
}
if (char === "a") {
return true;
}
if (char === "A") {
return true;
}
if (char === "E") {
return true;
}
if (char === "e") {
return true;
}
if (char === "i") {
return true;
}
if (char === "I") {
return true;
}
if (char === "O") {
return true;
}
if (char === "o") {
return true;
}
if (char === "AEIOU") {
return true;
}
if (char === "u") {
return true;
}
} ;
*/
function isVowel(char){
var vowel = ["i", "A", "e", "a", "E", "I", "o", "O", "u", "U"];
for (var i = 0; i < vowel.length; i++) {
if (char === vowel[i]) {
return true;
}
}
var consonant = ["B", "b", "C", "c", "D", "d"];
for (var i = 0; i < vowel.length; i++) {
if (char === consonant[i]) {
return false;
}
}
};
// YOUR CODE HERE
/**
* The `disemvowel` function combats the Internet
* Trolls by handily removing all of the vowels from
* their angry, hurtful comments. It's Super-Effective!
*
* @param {String} comment to disemvowel
* @return {String} cmmnt dsmvwld
*/
function disemvowel(comment){
return comment.replace(/[aeiou]/ig, "");
// YOUR CODE HERE
}
console.assert(disemvowel("bob") === "bb");
// Shorter test cases might be appreciated...
console.assert(
disemvowel("This website is for losers LOL!") === "Ths wbst s fr lsrs LL!"
);
/**
* The function `rovarspraket` will translate text into
* a "rövarspråket", i.e. double every consonant and
* place an occurrence of "o" in between them.
*
* For example, `rovarspraket("this is fun")` should
* return `"tothohisos isos fofunon"`
*
* @see https://en.wikipedia.org/wiki/R%C3%B6varspr%C3%A5ket
*
* @param {String} text to translate into "rövarspråket"
* @return {String} translation
*/
function rovarspraket(input){
return input.replace(/[^aeiou]/ig, "$&o$&");}
// tests correctly in replit.
// Feel free to provide additional examples...
console.assert(rovarspraket("a") === "a")
console.assert(rovarspraket("b") === "bob")
console.assert(rovarspraket("cat") === "cocatot")
console.assert(rovarspraket("javascript") === "jojavovasoscocroripoptot")
//console.assert(rovarspraket(0) === ("undefined"))