INSTRUCTIONS
Write a function that will return the count of distinct case-insensitive alphabetic characters and numeric digits that occur more than once in the input string. The input string can be assumed to contain only alphabets (both uppercase and lowercase) and numeric digits.
EXAMPLE
- "abcde" -> 0 # no characters repeats more than once
- "aabbcde" -> 2 # 'a' and 'b'
- "aabBcde" -> 2 # 'a' occurs twice and 'b' twice (
b
andB
) - "indivisibility" -> 1 # 'i' occurs six times
- "Indivisibilities" -> 2 # 'i' occurs seven times and 's' occurs twice
- "aA11" -> 2 # 'a' and '1'
- "ABBA" -> 2 # 'A' and 'B' each occur twice
ATTEMPT
function duplicateCount(text){
text = text.toUpperCase();
let count = 0;
for(let i of text){
if(text[i] === text[++i]){
count++
}
}
return count;
}
TEST CASE
- Test.assertEquals(duplicateCount(""), 0);
- Test.assertEquals(duplicateCount("abcde"), 0);
- Test.assertEquals(duplicateCount("aabbcde"), 2);
- Test.assertEquals(duplicateCount("aabBcde"), 2,"should ignore case");
- Test.assertEquals(duplicateCount("Indivisibility"), 1)
- Test.assertEquals(duplicateCount("Indivisibilities"), 2, "characters may not be adjacent")
TEST RESULTS
- Test Passed: Value == 0
- Expected: 0, instead got: 5
- Expected: 2, instead got: 7
- should ignore case - Expected: 2, instead got: 7
- Expected: 1, instead got: 14
- characters may not be adjacent - Expected: 2, instead got: 16
What am I missing here? I'm only passing the first test case.