I am learning javascript and I was applying the filters in javascript code, In below code, is there any possibility to improvise this code ? i was hoping if someone could tell me to how to use only one variable to store result of ages which are greater than 18 and less than 18. is there possibilty to use && operator in single return statement ? So that in final result I can show the data as
Voters under 18,21,24,30,32 category can vote. Voters under 10,15 category cannot vote
//Code
const ages = [10, 15, 18, 21, 24, 30, 32];
const ageResultabove = ages.filter((ageabove) => {
return ageabove >= 18;
});
const ageResultbelow = ages.filter((ageabelow) => {
return ageabelow < 18;
});
console.log(`Voters under ${ageResultabove} category can vote`);
console.log(`Voters under ${ageResultbelow} category cannot vote`);
Result should be like this Voters under 18,21,24,30,32 category can vote. Voters under 10,15 category cannot vote