Skip to content

Commit

Permalink
fix(Array/evenItem, Array/oddItem): performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
martinkr committed Nov 11, 2021
1 parent 5953fd3 commit cc30384
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/array/even-items.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @param {Array} arr
* @returns {Array}
*/
const fn = (arr, out = [], i) => { for (i = 0; i < arr.length; i = i + 2) out.push(arr[i]); return out; };
const fn = arr => arr.filter((_, index) => index % 2 === 0);


export default fn;
2 changes: 1 addition & 1 deletion src/array/odd-items.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @param {Array} arr
* @returns {Array}
*/
const fn = (arr, odds = [], i = 0) => { for (i = 0; i < arr.length; i++) (i & 1) && odds.push(arr[i]); return odds };
const fn = arr => arr.filter((_, i) => i & 1 === 1);


export default fn;

0 comments on commit cc30384

Please sign in to comment.