r/shittyprogramming • • Jun 07 '21
isEven with regex in javascript
const isEven = n => 'x'.repeat(n).replace(/xx/g, '') === '';
101
Upvotes
r/shittyprogramming • • Jun 07 '21
const isEven = n => 'x'.repeat(n).replace(/xx/g, '') === '';
2
u/MarceauKa Jun 07 '21
I don't even know why I tested that...
45
u/[deleted] Jun 07 '21
32
u/[deleted] Jun 07 '21
This is amazing. But in JavaScript, you can just “npm install is-even”. Which require is-odd.
14
u/csorfab Jun 07 '21
although I realize this is probably not shitty enough for the standards of this sub.
8
u/AndreasKralj Jun 07 '21
Can you explain what this is doing please?
5
u/[deleted] Jun 07 '21
This is my favorite isEven meme function. Totally absurd but elegant nonetheless
2
u/SkatingOnThinIce Jun 07 '21
That is great but mine will consider every instance of x in the string: