Merge branch 'master' of ssh://gitea.calebfontenot.com:25566/CCF_100/NoMoreAcronyms
This commit is contained in:
commit
8df43e3a79
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user