-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode Submission
More file actions
114 lines (98 loc) · 2.75 KB
/
Code Submission
File metadata and controls
114 lines (98 loc) · 2.75 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
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
const findSum = function(array) {
const sum = array.reduce((counter, current) =>{return counter + current}, 0)
return sum
};
const findFrequency = function(array) {
let mostOccurring = array[0]
let leastOccurring = array[0]
let currentAmount = 1
let mostFrequent = 0
let leastFrequent = array.length
let currentAmountLeast = 1
const changedArray = array.sort((a, b) => a.localeCompare(b))
for(let i = 1; i < changedArray.length; i++){
const curr = changedArray[i]
if(curr === changedArray[i - 1]){
currentAmount++
}
else{
currentAmount = 1
}
if(currentAmount > mostFrequent){
mostFrequent = currentAmount
mostOccurring = curr
}
}
for(let i = 1; i < changedArray.length; i++){
const curr = changedArray[i]
if(curr === changedArray[i - 1]){
currentAmountLeast++
}
else{
if(currentAmountLeast < leastFrequent){
leastFrequent = currentAmountLeast
leastOccurring = changedArray[i - 1]
}
currentAmountLeast = 1
}
}
return { most: mostOccurring, least: leastOccurring}
};
const isPalindrome = function(str) {
for(let a = 0; a < str.length; a++){
if(str[a].toLowerCase() !== str[str.length - (a + 1)].toLowerCase()){
return false
}
}
return true
};
const largestPair = function(array) {
let currentGreatestPair = array[0] * array[1]
for(let i = 0; i < array.length - 1; i++){
const currentProduct = (array[i] * array[i + 1])
if(currentProduct > currentGreatestPair){
currentGreatestPair = currentProduct
}
}
return currentGreatestPair
};
const removeParenth = function(str) {
const removeOpening = str.split('(')[0]
const removeClosing = str.split(')')[1]
return removeOpening + removeClosing
};
const scoreScrabble = function(str) {
const point1 = ['a', 'e', 'i', 'o', 'u', 'l', 'n', 'r', 's', 't']
const point2 = ['d', 'g']
const point3 = ['b', 'c', 'm', 'p']
const point4 = ['f', 'h', 'v', 'w', 'y']
const point5 = ['k']
const point8 = ['j', 'x']
const point10 = ['q', 'z']
let finalPoint = 0
for(let i = 0; i < str.length; i++){
const curr = str[i].toLowerCase()
if(point1.includes(curr)){
finalPoint += 1
}
else if(point2.includes(curr)){
finalPoint += 2
}
else if(point3.includes(curr)){
finalPoint += 3
}
else if(point4.includes(curr)){
finalPoint += 4
}
else if(point5.includes(curr)){
finalPoint += 5
}
else if(point8.includes(curr)){
finalPoint += 8
}
else if(point10.includes(curr)){
finalPoint += 10
}
}
return finalPoint
};