Hi Guys,
I am a bit struggling with the return for the below two scenarios, using .map and .filter functions.
why the return statement when using the .filter methods return the items in the items array rather then bollian (true or false) as the return is ( item.split(’’).reverse().join(’’) === item;) which if i return correctly, says it will return the comparision between two items.
really appreciate if someone can clarify me the below concept.
////////////using Map///////////////
var items = ['mum', 'dad', 'brother'];
items.map(function(item) {
return item.split('').reverse().join('') === item;
});
// returns [true, true, false]
///////////////////////////////////////
//////////////using Filter////////////////
var items = ['mum', 'dad', 'brother'];
items.filter(function(item) {
return item.split('').reverse().join('') === item;
});
// returns ['mum', dad']
//////////////////////////////////////////////