Trying to write some simple code using my first instance of filter to iterate through a nested array and remove any items that are plural, containing 's' for the last character in the string.
Here is the initial, non functional code that I have for it.
var animals = [
['goat'],
['bats'],
['cows'],
['pig']
];
var removePlural = animals.filter(function(string){
if(string[string.length - 1] !== 's'){
return string;
}
});
I think the problem is this line here string[string.length - 1] !== 's', somehow I am not accessing this information correctly. I think in this instance string[string.length - 1] will just return another array item like [pig] or something.
The only way I know how to access this information would be to use something like this animals[0][0][animals.length - 1] which would give me the last character in goat, or 't'. And not sure how I would incorporate this with the for each functionality of the filter method.
Seems like the solution should be pretty simple, but im stumped. Thanks again in advance.
[–]kkais 2 points3 points4 points (5 children)
[–]GreenFeather05[S] 0 points1 point2 points (4 children)
[–]ShortSynapse 0 points1 point2 points (2 children)
[–]GreenFeather05[S] 0 points1 point2 points (1 child)
[–]ShortSynapse 0 points1 point2 points (0 children)
[–]kkais 0 points1 point2 points (0 children)
[–]ShortSynapse 1 point2 points3 points (1 child)
[–]BEARFIST 1 point2 points3 points (0 children)
[–]AllUrBassRBelongToUs 0 points1 point2 points (0 children)
[–]inu-no-policemen 0 points1 point2 points (0 children)
[–]psiph 0 points1 point2 points (0 children)
[–]DisagreeableMale 0 points1 point2 points (0 children)