JavaScript: Same parity

Last update: 02 Apr 23:20
1
Student
100%
Completion rate

sameParityFilter.js

Implement and export as default a function that takes an array as input and returns a new one consisting of elements that have the same parity as the first element of the input array.

Examples

sameParity([-1, 0, 1, -3, 10, -2]); // [-1, 1, -3]
sameParity([2, 0, 1, -3, 10, -2]); // [2, 0, 10, -2]
sameParity([]); // []

For full access to the challenge you need a professional subscription.

A professional subscription will give you full access to all Hexlet courses, projects and lifetime access to the theory of lessons learned. You can cancel your subscription at any time.

Get access
130
courses
1000
exercises
2000+
hours of theory
3200
tests