-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode Challenge
More file actions
76 lines (62 loc) · 1.46 KB
/
Copy pathCode Challenge
File metadata and controls
76 lines (62 loc) · 1.46 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
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 count = array.reduce(function (allLetters, char) {
if (char in allLetters) {
allLetters[char]++
}
else {
allLetters[char] = 1
}
return allLetters
}, {})
return count
};
const isPalindrome = function (str) {
let arr = Array.from(str);
let check = arr.reverse();
check = check.join('')
if (str === check) {
return true;
} else {
return false;
}
// your code here - don't forget to return a boolean!
};
const largestPair = function (arr) {
let myResult = 0
let i = 0
let maxIndex = arr.length - 1
do {
if (arr[i] * arr[i + 1] > myResult) {
myResult = arr[i] * arr[i + 1]
} else {
myResult = myResult
}
i++
} while (i < maxIndex)
return myResult;
};
const removeParenth = function (str) {
let arr1 = str.replace(/ *\([^)]*\) */g, "")
return arr1
};
const scoreScrabble = function (str) {
let letter = str;
function letterValue(word) {
let points = { a: 1, e: 1, i: 1, o: 1, u: 1, l: 1, n: 1, r: 1, s: 1, t: 1, d: 2, g: 2, b: 3, c: 3, m: 3, p: 3, f: 4, h: 4, v: 4, w: 4, y: 4, k: 5, j: 8, x: 8, q: 10, z: 10 },
sum = 0,
i;
word = word.toLowerCase();
for (i = 0; i < word.length; i++) {
sum += points[word[i]] || 0;
}
return sum;
}
return letterValue(letter)
};