While developing I am having lint error for this function
Do not nest ternary expressions.eslintno-nested-ternary
How can I convert the below funciton into switch case? Or any other such that I solve the es lint error?
getDaySuffix = day => (day === (1 || 21 || 31) ? 'st' : day === (2 || 22) ? 'nd' : day === (3 || 23) ? 'rd' : 'th');
Also Can anyone help me with this function too,in below function I am getting an error of
Assignment to property of function parameter 'carry'.
How can I solve this above error with below function? How can I re-write the function without changing the function logic? And solve the eslint error too.
const filter = selectedFilter[0].conditions.reduce(
(carry, current) => {
if (current.field === 'access_group_uuid') {
// eslint-disable-next-line in next line getting error at carry
carry[current.field] = (carry[current.field] || []).concat(
current.value,
);
} else {
// eslint-disable-next-line in next line getting error at carry
carry[current.field] = carry[current.field] ?
[carry[current.field], current.value] :
current.value;
}
return carry;
}, {},
);
Edit -- For second function with example
const data = {
executed:[
{_id: "5f23d394cd 480e300", field: "name", value: "Jolly", operator: "equal"},
{_id: "5f30d39f4cd8d0e301", field: "status", value: "EXPIRED", operator: "equal"},
{_id: "5f230d39001480e302", field: "grp", value: "874-3-11-4-56", operator: "equal"},
{_id: "59f4cd8d001480e303", field: "grp", value: "873-5-12-4-77", operator: "equal"}
],
created_at: "2020-07-30T18:11:05.992Z",
name: "Kind Find",
_id: "1f230d39f4cd8d441480e2dd"
}
console.log(
data.executed.reduce((carry, current) => {
if (current.field === 'grp') {
// eslint-disable-next-line no-param-reassig
carry[current.field] = (carry[current.field] || []).concat(current.value);
} else {
// eslint-disable-next-line no-param-reassig
carry[current.field] = carry[current.field] ? [carry[current.field], current.value] : current.value;
}
return carry;
}, {})
);