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) {
|
function countChars(string) {
|
||||||
var outputString = "";
|
var outputString = "";
|
||||||
string = string.toLowerCase();
|
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) {
|
for (let i = 0; i < string.length; ++i) {
|
||||||
let currentChar = string.charAt(i);
|
let currentChar = string.charAt(i);
|
||||||
let arrayIndex = currentChar.charCodeAt(0) - 97;
|
let arrayIndex = currentChar.charCodeAt(0);
|
||||||
if (string.charAt(i).search(/^[a-z]+$/) === 0) {
|
if (string.charAt(i).search(/^[A-Z]+$/) === 0) {
|
||||||
letterCount[arrayIndex]++;
|
arrayIndex += 32; //This should make it cast any uppercase characters to lowercase
|
||||||
}
|
}
|
||||||
|
letterCount[arrayIndex]++;
|
||||||
}
|
}
|
||||||
for (let i = 0; i < letterCount.length; ++i) {
|
for (let i = 0; i < letterCount.length; ++i) {
|
||||||
if (letterCount[i] > 0) {
|
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;
|
return outputString;
|
||||||
|
Loading…
Reference in New Issue
Block a user