#2024 Day 16 Discussion Thread
20 messages · Page 1 of 1 (latest)
I hated this one because of what is used.
I had it so quickly, but kept getting the function was returning N/A. Just re-ran it a few times and it went through.
I can't seem to make this one work. Output keeps being N/A but console.logs show 5. Anyone found a solution?
||Two steps, first $ checks something ends with in Regex, and \ to escape something, like a full stop maybe?||
I've also tried like that. It would look like this, no?
|| function countSnowReports(paths) {
const regex = //snow_report.txt$/;
const matches = paths.filter(file => regex.test(file));
console.log(matches.length)
return matches.length;
} ||
||In Regex you need to escape certain characters: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Character_escape||
I don't know what's wrong anymore haha
||function countSnowReports(paths) {
const regex = //snow_report.txt$/;
const matches = paths.filter(file => regex.test(file));
return matches.length;
}||
||Ok, I'll give you one last hint to see if you can get it, reset the challenge, and you should see the use of character escaping, one more character needs escaping, and check it ends with this string. Give that a try, if not I can show you how I solved it.||
I surrender 😦
||It's a two step fix, first we need to escape the dot \. and make sure we test that is ends with this string $.
/\/snow_report\.txt$/
```||
Thank you!
🤔 I think I had that before. I'm trying it and it doesn't work:
||function countSnowReports(paths) {
// Regex to match only "snow_report.txt" at the end of any path
const regex = //snow_report.txt$/;
// Count how many files match the regex
const matches = paths.filter(file => regex.test(file));
return matches.length;
}||
Am I missing something?
||Yes, you're not espacing the slash (\/) and dot (\.) ||
Sorry, that's when copy pasting
this is the code:
||That should be it yes||
Found the problem!!! Thank you so much, @spring island
I was returning matches.length instead of matches
done! (before looking at this channel)
am I allowed to blame the yeti for thinking ||regexes are better than .endsWith()||?
||Aah, guess we both had blinders, I wasn't even paying attention to if you have changed the return value. 😂||
As much as I don't like ||regex, it does give you a wider array of things to test for than just .endsWith() for sure.||