HackDiary#012
8 comments
Write a comment
I prefer: value.startsWith('"') && value.endsWith('"') ? value.slice(1, -1) : value It's readable, easier to understand.
Creator
Thanks for your comment!
I too prefet the 1st one as it is more readable. For regexp I normally would extract the regexp in a constant and name it to actually what it is doing. And naming is not easy too ;)
Creator
Thanks. To be precise, the first one actually needs to be this: ``` value.length > 1 && value.startsWith('"') && value.endsWith('"') ? value.slice(1, -1) : value ```
I prefer second one. simple and learn REGEX!
Creator
Thanks. This is interesting. Some say one is easier to another, and some say the first one is faster. They are from various perspectives.
Regex is so complicated and difficult to parse. I'd prefer the first one for readability, but I do wish I had regex super powers!
Creator
Yeah, this one is simple but usually regex is hard to read.