forked from twowaits/make-pull-request
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase.js
30 lines (25 loc) · 899 Bytes
/
base.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
// function to check whether string is an email or not.
function checkEmail(email) {
var re = /\S+@\S+\.\S+/;
return re.test(email);
}
console.log(checkEmail('[email protected]'));
// function to remove all slashes, empty spaces in beginning and end.
function removeSlash(string) {
var slash = true;
while (slash) {
string = string.trim().replace(/^\/+|\/+$/g, "");
if (!(string[0] === '/' || string[0] === " " || string.slice(-1) === '/' || string.slice(-1) === " ")) {
slash = false;
}
}
return string;
}
console.log(removeSlash("/ /// / hello/world/ / // /"));
// function make alternative chars as lowercase and UPPERCASE.
function toOppositeCase(string) {
return string.split('').map(function (c, i) {
return i & 1 ? c.toUpperCase() : c.toLowerCase();
}).join('');
}
console.log(toOppositeCase("soMeStrinG"));