Skip to content

Latest commit

 

History

History
25 lines (17 loc) · 702 Bytes

removing-elements.md

File metadata and controls

25 lines (17 loc) · 702 Bytes

Removing Elements 8 Kyu

LINK TO THE KATA - LISTS ARRAYS FUNDAMENTALS

Description

Take an array and remove every second element from the array. Always keep the first element and start removing with the next element.

Example:

["Keep", "Remove", "Keep", "Remove", "Keep", ...] --> ["Keep", "Keep", "Keep", ...]

None of the arrays will be empty, so you don't have to worry about that!

Solution

const removeEveryOther = arr => {
  return arr.filter((element, index) => index % 2 === 0)
}