From abc805e9b4f04b03efc0415fbe938d9fa1a53c0b Mon Sep 17 00:00:00 2001 From: Caleb Fontenot Date: Tue, 4 Apr 2023 17:40:22 -0500 Subject: [PATCH] Add countChars function --- commands/countChars.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/commands/countChars.ts b/commands/countChars.ts index d83258d..325bfad 100644 --- a/commands/countChars.ts +++ b/commands/countChars.ts @@ -43,8 +43,12 @@ function countChars(string) { letterCount[arrayIndex]++; } 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) { - outputString += "Number of " + String.fromCharCode(i).toUpperCase() + "'s: " + letterCount[i] + "\n"; + outputString += "Number of " + currentChar + "'s: " + letterCount[i] + "\n"; } } return outputString;