While working on solving this exercise i faced an issue with the counter varible, it wasn’t incrementing it says 0 forever
const lettersFound = {}
export const isPangram = (sentence) => {
let re = /[a-z]/ig
let letters = sentence.match(re)
if (!letters) return false;
let counter = 0
for (let i = 0; i < letters.length; i++) {
let letter = letters[i].toLowerCase()
if (lettersFound[letter]) {
continue
}
lettersFound[letter] = "whatever"
counter++
if (counter == 26) {
return true
}
}
return false
};
it’s a bug i suppose
glennj
2
Where do you increment the counter value?
i apologize i edited the code.
kindly check it again
glennj
4
Should I use semicolons in JavaScript?
Additionally, you don’t initialize lettersFound
in between invocations of the function. You don’t want to let the last test pollute the current test.
Thanks for the reply Glennj.
the thing is i tried the same code on vscode and it worked fine this is why I’m reporting it as a bug
glennj
6
It’s working on vscode because you’re only running one test at a time. Add this as the first line of the function
console.log([sentence, lettersFound]);
You’ll see from the exercism test output that the lettersFound map is not empty when it should be.
3 Likes