-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
69 lines (58 loc) · 1.8 KB
/
index.js
File metadata and controls
69 lines (58 loc) · 1.8 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
module.exports = Phrase;
// Adds `reverse` to all strings.
String.prototype.reverse = function() {
return Array.from(this).reverse().join("");
}
//exercises
String.prototype.blank = function() {
return !!(this.match(/^\s*$/g));
}
Array.prototype.last = function() {
return this[this.length-1]
}
// function palindrome(string) {
// let lowerstring=string.toLowerCase()
// return lowerstring === reverse(lowerstring);
// }
function emailsplit(email) {
let uemail = email.toLowerCase();
let username = uemail.split("@")[0];
let domain = uemail.split("@")[1];
return `Username: ${username}. Domain: ${domain}`;
}
// Defines a Phrase object.
function Phrase(content) {
this.content = content;
this.louder = function() {return this.content.toUpperCase();}
//tolowercase processor
this.processor = function(string) {
return string.toLowerCase();
}
// Returns content processed for palindrome testing.
this.processedContent = function processedContent() {
return this.processor(this.letters());
}
// Returns the letters in the content.
this.letters = function letters() {
const letterRegex = /[a-z]/gi;
return (this.content.match(/[a-z]/gi) || []).join("");
}
// Returns true if the phrase is a palindrome, false otherwise.
this.palindrome = function palindrome() {
if (this.processedContent()) {
return this.processedContent() === this.processedContent().reverse();
} else {
return false;
}
}
}
// Defines a TranslatedPhrase object.
function TranslatedPhrase(content, translation) {
this.content = content;
this.translation = translation;
// Returns translation processed for palindrome testing.
this.processedContent = function processedContent() {
return this.processor(this.translation);
}
}
TranslatedPhrase.prototype = new Phrase();