Hey there, I've been working on incorporating the array filter property to separate subarrays that are greater than and less than 3 into two distinct functions. Unfortunately, I'm a bit stuck on how to continue fixing my functions. Can someone provide assistance and also explain why I'm currently getting unexpected results?
var subarrays = [
[1,2,3],
['a','b','c','d','e'],
['hippopatamus', 'zebra', 'crocodile','lion'],
[false, 2]
];
var greaterThan3 = function(array){
for(var i = 0; i < array.length; i ++){
if(array[i].length > 3) {
return array[i];
} else {
return false;
}
}
};
var lessThan3 = function(array){
var arr = [];
for(var i = 0; i < array.length; i ++){
if(array[i].length < 3){
arr.push(array[i]);
} else {
return false;
}
}
return arr;
};
After running the greater than function, only the animal names appear. It appears that the "length" parameter is referencing the length of words in the arrays rather than the length of the entire array itself. How can I target the length of the whole array instead? When using the less than function, I'm only getting single letters returned. Once again, my goal is to focus on the length of the array as a whole, not just its contents. Any help would be greatly appreciated. Thank you!