whAT are the main work of these .map and .reduce and .filter
and why we use arrow (item) =>
can somebody explain .
the use of arrow
whAT are the main work of these .map and .reduce and .filter
and why we use arrow (item) =>
can somebody explain .
the use of arrow
Arrow functions arenβt necessary for .map
, .reduce
, or .filter
, nor the other way around. Arrow functions are (for most purposes) simply a more concise syntax for writing functions.
const ANIMAL_EMOJIS = ['πΆ', 'π', 'π’', 'π¦', 'π', 'π'];
// the following two versions both return ['πΆ', 'π']
// version 1:
function isDogEmoji(str) {
return str === 'πΆ' || str === 'π';
}
ANIMAL_EMOJIS.filter(isDogEmoji);
//version 2:
ANIMAL_EMOJIS.filter(str => str === 'πΆ' || str === 'π');