I created a code to solve an exercise that expects an variable that says if a string is a pangram or not. The code that I am working on should return all the letters of a sentence in an variable, cause I pretend to compare if that variable have all the alphabet letters. My issue is that the IF condition just work "every other day".
For the sentence "the quick brown fox jumps over the lazy dog", it returns: "teqikbonfxjmsoetelzdg"
For the sentence "abcdefghijklmnopqrstuvwxyz", it returns: "acegikmoqsuwy"
export const isPangram = (str) => {
var result = '';
var reg = /[a-z]/ig;
var splited = str.split('');
for(let x = 0; x < splited.length; x++){
if(reg.test(splited[x]) === true){
result = result + splited[x];
}
}
}
Aucun commentaire:
Enregistrer un commentaire