My pangram function should return true when I have every letter of the alphabet and should return false when I don’t have every letter of the alphabet in the sentence that my function uses as an argument.
And if you have more efficient solution, right now I just prefer using this inefficient algorithm(assuming that a more efficient solution to my problem may exist).
but ch is a single character at a time. So it is one single character. It can’t be all the alphabet letters at once
you do something like
let ch = "a";
if (ch == "a" && ch == "b") {
return true;
} else {
return false;
}
it will return false as a single character can’t be equal to two different characters at the same time. When you use && both comparisons need to be true for the whole statement to be true
but the forloop is supposed to make it so that it traverses through every letter of the string given and my if statement is supposed to check if every letter of the alphabet is represented in my sentence.
I just completed this one on Codewars so here is my solution:
function isPangram(string) {
//create a lowercase string with everything replaced except letters
string = string.toLowerCase().replace(/[^a-z]/g, '');
//array with letters
let letterArray = [];
//loop over string, if index = -1, add item to array
for (let i = 0; i < string.length; i++) {
if (letterArray.indexOf(string.charAt(i)) === -1) {
letterArray.push(string.charAt(i));
}
}
//count array.length, if equal to 26, return true, otherwise false
return letterArray.length === 26;
}