How to satisfy an array of callback strings?
This is my first shot:
const planLimits = {plan1: {condition1: 50, ...}}
function initialisePlanLimits(planLimits) {
const limits = new Map();
Object.keys(planLimits).map((planId) => (
const limitMap = new Map(Object.entries(planLimits[planId]));
limits.set(planId, limitMap);
));
return limits;
}
Linter marks this error: error Expected to return a value in this function array-callback-return
So, I changed this version:
function initialisePlanLimits(planLimits) {
const limits = new Map();
Object.keys(planLimits).map((planId) => (
limits.set(planId, new Map(Object.entries(planLimits[planId])))
));
return limits;
}
It throws another error Unexpected parentheses around single function argument having a body with no curly braces arrow-parens
My questions:
1) I believe I can fix my first version by sticking return null
to curry. But is there a better, more elegant way? Fake return statement doesn't make sense in this context
2) Why doesn't the second version work? Isn't this equivalent to the first version?
If I use forEach
instead map
, it doesn't produce a array-callback-return
lint error
Object.keys(planLimits).forEach((planId) => (
const limitMap = new Map(Object.entries(planLimits[planId]));
limits.set(planId, limitMap);
));
With this sample ReactJS code showing a group of elements ...
showclasses.map( (showclass, index) => {
$('.' + showclass).show();
});
I am getting this error ...
Expected to return a value in arrow function array-callback-return
The error goes away if I add one return to the above function, for example:
showclasses.map( (showclass, index) => {
return $('.' + showclass).show();
});
map () is powerful. Do not drop this tool.