diff --git a/src/array/even-items.js b/src/array/even-items.js index 2b78db9..4e75ad5 100644 --- a/src/array/even-items.js +++ b/src/array/even-items.js @@ -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; diff --git a/src/array/odd-items.js b/src/array/odd-items.js index fe57dee..3eb9979 100644 --- a/src/array/odd-items.js +++ b/src/array/odd-items.js @@ -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;