-
Notifications
You must be signed in to change notification settings - Fork 0
/
EasyCoderByte.js
61 lines (54 loc) · 1.22 KB
/
EasyCoderByte.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
function firstReverse(str) {
return str.split('').reverse().join('');
}
function firstReverse(str) {
for (var i=0; i<str.length; i++) {
rev_s += str.substring(i-1, i);
}
return rev_s;
}
function firstFactorial(num) {
factorial = 1;
for (var i=num; i>0; i--) {
factorial *= i;
}
return factorial;
}
function longest_word(sen) {
var words = sen.match(/[a-z]{0,}/gi);
longest_length = 0;
longest_index = 0;
for (var i=0; i<words.length; i++) {
if (words[i].length > longest_length) {
longest_length = words[i].length;
longest_index = i;
}
}
return words[longest_index];
}
function letter_changes(str) {
var alphabet1 = '';
var alphabet2 = '';
var newstring1 = '';
var newstring2 ='';
for (var i=0; i<str.length; i++) {
if (str.charAt(i) == 'z') {
newstring1 += 'a';
}
else if (str.charAt(i) == 'Z') {
newstring1 += 'A';
}
else if (alphabet1.indexOf(str.charAt(i)) != -1) {
newstring1 += alphabet1[alphabet1.indexOf(str.charAt(i))+1];
}
else if (alphabet2.indexOf(str.charAt(i)) != -1) {
newstring1 += alphabet2[alphabet2.indexOf(str.charAt(i))+1];
}
else {
newstring1 += str.charAt(i);
}
}
for (var i=0; i<str.length; i++) {
if (newstring1.charAt(i) == 'a') {};
}
}