Merge branch 'master' of ssh://gitea.calebfontenot.com:25566/CCF_100/NoMoreAcronyms

master
Chloe Fontenot 🏳️‍⚧️ 2023-04-04 17:31:55 +07:00
commit 487419e4fe
1 changed files with 6 additions and 5 deletions

@ -33,17 +33,18 @@ module.exports = {
function countChars(string) {
var outputString = "";
string = string.toLowerCase();
var letterCount = Array(26).fill(0); // Creates an array with 26 values, all equaling 0.
var letterCount = Array(65535).fill(0); // Creates an array with 26 values, all equaling 0.
for (let i = 0; i < string.length; ++i) {
let currentChar = string.charAt(i);
let arrayIndex = currentChar.charCodeAt(0) - 97;
if (string.charAt(i).search(/^[a-z]+$/) === 0) {
letterCount[arrayIndex]++;
let arrayIndex = currentChar.charCodeAt(0);
if (string.charAt(i).search(/^[A-Z]+$/) === 0) {
arrayIndex += 32; //This should make it cast any uppercase characters to lowercase
}
letterCount[arrayIndex]++;
}
for (let i = 0; i < letterCount.length; ++i) {
if (letterCount[i] > 0) {
outputString += "Number of " + String.fromCharCode(i + 97).toUpperCase() + "'s: " + letterCount[i] + "\n";
outputString += "Number of " + String.fromCharCode(i).toUpperCase() + "'s: " + letterCount[i] + "\n";
}
}
return outputString;