Even All the Way

Published by Matt in

Given an array of numbers, return an array which contains all the even numbers in the original array, which also have even indices.

Examples

getOnlyEvens([1, 3, 2, 6, 4, 8]) ➞ [2, 4]

getOnlyEvens([0, 1, 2, 3, 4]) ➞ [0, 2, 4]

getOnlyEvens([1, 2, 3, 4, 5]) ➞ []

Notes

Arrays start at index 0.

Watch a quick demo on how Edabit works.