-
Notifications
You must be signed in to change notification settings - Fork 0
/
countingDuplicates.js
31 lines (24 loc) · 1012 Bytes
/
countingDuplicates.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
function duplicateCount(text){
text = text.toLowerCase()
let lettersThatAppearMoreThanOnce = []
for (let letter of text) {
if (appearsMoreThanOnce(text,letter) && !lettersThatAppearMoreThanOnce.includes(letter)) {
lettersThatAppearMoreThanOnce.push(letter)
}
}
return lettersThatAppearMoreThanOnce.length
}
let appearsMoreThanOnce = (word, letter) => {
if ((word.split(letter).length - 1) > 1) {
return true
} else return false
}
/*
Parameters: an alphanumeric string, so no spaces or special characters
Return value: An integer which represents how many distinct chars are repeated, treating all letters the same
regardless of capitalization
Example: "aabBcde" => 2, because there's a and b
Psuedocode:
For each letter, check if it appears more than once. Add the lowercase version of it to the lettersWhoAppearMoreThanOnce
array, if it is not already in there. Then return the length of this array
*/