2 ms·
This isn't a particularly bad one, but it's the first one that popped into my head, and is somewhat unexpected unless you're very familiar with how JavaScript R
by tlrobinson 17y ago
This isn't a particularly bad one, but it's the first one that popped into my head, and is somewhat unexpected unless you're very familiar with how JavaScript RegExp's "exec" method works:
> r = /^x$/g
/^x$/g
> r.exec("x")
x
> r.exec("x")
null
> r.exec("x")
x
> r.exec("x")
null
(When exec is used on a regex with the global flag it will remember the position of the end of the last match and perform the next match beginning at that offset. Obviously will cause very bizarre behavior if you expect it to be idempotent...)