Skip to content

Conversation

kemitchell
Copy link

Here's the current code:

  1	module.exports = remove
  2
  3	function remove (arr, i) {
* 4	  if (i >= arr.length || i < 0) return
  5	  var last = arr.pop()
* 6	  if (i < arr.length) {
  7	    var tmp = arr[i]
  8	    arr[i] = last
  9	    return tmp
 10	  }
 11	  return last
 12	}

I noticed with the prior guard on line 3, the condition on line 6 can be !==, rather than <. In Ye Olde Days, we used to expect that'd be faster.

I'm usually seriously skeptical of "microbenchmarks", especially in interpreted languages like JavaScript. But since the whole point here is perf, I thought I'd pass along, so you can make the choice.

Feel free to drop this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant