Tuesday, July 9, 2019

Day 093: Copy & Paste Hell, Diffchecker is Your Friend

I'm still working through the freeCodeCamp's intermediate algos. Next up was this problem Intermediate Algorithm Scripting: Convert HTML Entities which asks to convert the characters &, <, >, " (double quote), and ' (apostrophe), in a string to their corresponding HTML entities.

Easy peasy! I thought to myself since I am starting to get very comfortable with Regular Expressions and that was what I intended to use. I wrote up my code by copying and pasting the HTML entities from the of test cases below the buttons.

Huh?

I press run the tests... and for some reason, some parts did not work? I spent the next 30 mins wondering wtf I did wrong. Googled up why it didn't work as well as the solutions on how to make it work. Working through it in the console or codesandbox gave me the correct answer with what I originally wrote as well. By all accounts on StackOverflow and such, I had the right answer... but the tests were not passing on FCC. 

PS get a codesandbox.io account and you can code anywhere!

I sometimes check out the hints but I really hate looking at the solution. But after nearly an hour (my cue to start getting help) at this, I gave up and looked at how FCC did it.... and it was nearly identical to their intermediate solution. WTF?! And yes, I also checked to make sure their solution actually passed their test and it did.


And then it finally dawned on me that I might have some weird characters somewhere that FCC is not reading, so I fired up Diffchecker to confirm my suspicions..... and yep.. there's a hidden blank character that I got from when I copied and pasted the HTML entities from the FCC site.

After removing those bits from my code, the tests all passed with flying colors. /sigh


No comments:

Post a Comment