-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubmission.js
128 lines (85 loc) · 2.56 KB
/
submission.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
const findSum = function(array) {
let sum = 0;
for (let i = 0; i < array.length; i++) {
sum += array[i];
}
return sum;
};
const findFrequency = function(array) {
let mostLeast = {
most: 0,
least: 0
};
function mostFrequent (array){
return array.sort((a,b) =>
array.filter(v => v===a).length
- array.filter(v => v===b).length
).pop();
}
function leastFrequent (array){
return array.sort((a,b) =>
array.filter(v => v===b).length
- array.filter(v => v===a).length
).pop();
}
mostLeast.most = mostFrequent(array);
mostLeast.least = leastFrequent(array);
return mostLeast;
};
const isPalindrome = function(str) {
for (let i = 0; i < str.length; i++) {
for (let j = str.length -1; j >= 0; j--) {
if (str[i] != str[j]) {
return false;
} else {
return true;
}
}
}
};
const largestPair = function(array) {
const products = [];
for (let i = 0; i < array.length -1; i++) {
products.push(array[i] * array[i + 1]);
}
return Math.max.apply(Math, products);
};
const removeParenth = function(str) {
let firstParenth = str.split('(');
let secondParenth = firstParenth[1].split(')');
let backOfString = secondParenth[1];
let frontOfString = firstParenth[0];
let combined = frontOfString + backOfString;
return combined;
};
const scoreScrabble = function(str) {
const catchNumbers = [];
const rateLetters = () => {
for (let i = 0; i < str.length; i++) {
if (str[i] === 'a' || str[i] === 'e' || str[i] === 'i' || str[i] === 'o' || str[i] === 'u' || str[i] === 'l' || str[i] === 'n' || str[i] === 'r' || str[i] === 's' || str[i] === 't') {
catchNumbers.push(1);
} else if (str[i] === 'd' || str[i] === 'g') {
catchNumbers.push(2);
} else if (str[i] === 'b' || str[i] === 'c' || str[i] === 'm' || str[i] === 'p') {
catchNumbers.push(3);
} else if (str[i] === 'f' || str[i] === 'h' || str[i] === 'v' || str[i] === 'w' || str[i] === 'y') {
catchNumbers.push(4);
} else if (str[i] === 'k') {
catchNumbers.push(5);
} else if (str[i] === 'j' || str[i] === 'x') {
catchNumbers.push(8);
} else if (str[i] === 'q' || str[i] === 'z') {
catchNumbers.push(10);
}
}
}
rateLetters(str);
const findSum = function(array) {
let sum = 0;
for (let i = 0; i < array.length; i++) {
sum += array[i];
}
return sum;
}
return findSum(catchNumbers);
};