-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalgorithm9.html
More file actions
41 lines (29 loc) · 867 Bytes
/
algorithm9.html
File metadata and controls
41 lines (29 loc) · 867 Bytes
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
<!DOCTYPE html>
<html>
<body>
<script>
//https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/missing-letters
//Find the missing letter in the passed letter range and return it.
//If all letters are present in the range, return undefined.
function fearNotLetter(str) {
var length = str.length;
var newArr = str.split("");
newArr = newArr.map(a => a.charCodeAt());
for (var i=0; i<(newArr.length)-1; i++) {
var misChar = newArr[i] + 1;
if (misChar == newArr[i+1]) {
continue;
} else {
return String.fromCharCode(misChar);
}
}
return undefined;
}
//tests
console.log(fearNotLetter("abce"));
console.log(fearNotLetter("abcdefghjklmno"));
console.log(fearNotLetter("stvwx"));
console.log(fearNotLetter("abcdefghijklmnopqrstuvwxyz"));
</script>
</body>
</html>