Hacker News new | ask | show | jobs
by mattmanser 3255 days ago
You can actually just do this:

    for (var i = 0, l = details.responseHeaders.length; i < l; ++i) {
1 comments

I would have done that, but because of the splicing you don’t actually want ++i every time. That’s why I rewrote it to a while loop.

Even then you could do it as a for loop with an empty increment clause, of course. Or even use a one-liner for loop with no body:

  function blockCookies(details) {
    for (var headers = details.responseHeaders, i = headers.length - 1; i > -1; headers[i].name === "Set-Cookie" ? headers.splice(i, 1) : i--);
    return {responseHeaders: headers};
  }
But that’s crazy talk. Leave optimisations that to the minifier if it feels so disposed.