JavaScript: Search and Don’t Replace (2008)
johnresig.com
JavaScript: Search and Don’t Replace (2008)
1–10 of 46 posts
Re: JavaScript: Search and Don’t Replace (2008)
#2Re: JavaScript: Search and Don’t Replace (2008)
#3Re: JavaScript: Search and Don’t Replace (2008)
#4Please give me an 80 kloc project full of this kind of smartness, preferably minefied.
Re: JavaScript: Search and Don’t Replace (2008)
#5Jamie Zawinski
Re: JavaScript: Search and Don’t Replace (2008)
#6> Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. Jamie Zawinski
Re: JavaScript: Search and Don’t Replace (2008)
#7Re: JavaScript: Search and Don’t Replace (2008)
#8> Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. Jamie Zawinski
This is a funny quote. I really hope it doesn't keep people from learning regular expressions, which are actually not as hard as they are often portrayed and extremely powerful and efficient, as demonstrated in this post.
Re: JavaScript: Search and Don’t Replace (2008)
#9Object.entries(Array.from(new URLSearchParams("foo=1&foo=2&foo=3&blah=a&blah=b").entries()).reduce((a,[k,v]) => ({ ...a, [k]: [...a[k] ?? [], v] }), {})).map(([key, values]) => `${key}=${values.join(",")}`).join("&");
Re: JavaScript: Search and Don’t Replace (2008)
#10Still quite a straightforward and elegant solution, but I'm curious what the performance is like these days compared to alternatives. The better the JIT gets, the more allocation (of the many intermediate strings, and the thrown-away string) would seem to matter.
Of course, that could have been based on a misunderstanding on the part of the person talking with me, though I would guess it matters how many intermediates (or array elements) you're talking about.
Sort of a miracle that you mostly don't need to worry about this stuff today, even running on a $100 mobile device.