I prefer:
value.startsWith('"') && value.endsWith('"') ? value.slice(1, -1) : value
It's readable, easier to understand.
Daishi KatoCreator
Thanks for your comment!
nehaldamania
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 ;)
Daishi KatoCreator
Thanks.
To be precise, the first one actually needs to be this:
```
value.length > 1 && value.startsWith('"') && value.endsWith('"') ? value.slice(1, -1) : value
```
iamswain
I prefer second one. simple and learn REGEX!
Daishi KatoCreator
Thanks.
This is interesting. Some say one is easier to another, and some say the first one is faster. They are from various perspectives.
qodesmith
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!
Daishi KatoCreator
Yeah, this one is simple but usually regex is hard to read.
8 comments
I prefer: value.startsWith('"') && value.endsWith('"') ? value.slice(1, -1) : value It's readable, easier to understand.
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 ;)
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!
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!
Yeah, this one is simple but usually regex is hard to read.