const oddItems = arr => arr.filter((_, i) => i & 1 === 1);
Enter fullscreen mode
Exit fullscreen mode
Ret...
Some comments have been hidden by the post's author - find out more
For further actions, you may consider blocking this person and/or reporting abuse
Not looked for faster methods yet, but the current one seems overly verbose. Also, what is
whichfor?Binary filters are even faster than the modulo:
Faster still if you omit the unnecesary
=== 1- it's about even on Firefox, but consistently quicker on Chrome (10-15%) - linkMuch faster again (on all tested browsers):
Hi Jon Randy,
I updated the benchmark on hasty - impressive improvement!
I updated the code and the article.
Thank you for the improved code.
Cheers!
Thank you!
If you are already using a for loop, you can also jump 2 steps on every iteration: