Add countChars function
This commit is contained in:
parent
2e13184c70
commit
abc805e9b4
@ -43,8 +43,12 @@ function countChars(string) {
|
|||||||
letterCount[arrayIndex]++;
|
letterCount[arrayIndex]++;
|
||||||
}
|
}
|
||||||
for (let i = 0; i < letterCount.length; ++i) {
|
for (let i = 0; i < letterCount.length; ++i) {
|
||||||
|
let currentChar = String.fromCharCode(i).toUpperCase();;
|
||||||
|
if (currentChar.charCodeAt(0) == 10 || currentChar.charCodeAt(0) == 13 || currentChar.charCodeAt(0) == 30 || currentChar.charCodeAt(0) == 115 || currentChar.charCodeAt(0) == 21 || currentChar.charCodeAt(0) == 118) {
|
||||||
|
currentChar = "newline";
|
||||||
|
}
|
||||||
if (letterCount[i] > 0) {
|
if (letterCount[i] > 0) {
|
||||||
outputString += "Number of " + String.fromCharCode(i).toUpperCase() + "'s: " + letterCount[i] + "\n";
|
outputString += "Number of " + currentChar + "'s: " + letterCount[i] + "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return outputString;
|
return outputString;
|
||||||
|
Loading…
Reference in New Issue
Block a user