это результат, которого я пытаюсь достичь здесь If the "settlementDesc" in messages, has a string without ":" or " ", omit that entry of messages. If all entries are omitted in the messages, then remove the messages entry from the drug price response.
, поэтому в приведенном ниже коде выполняется противоположная операция, есть идеи, что реализовано неправильно?
main.js
const messages = [
{
"settlementCode": "99",
"settlementDesc": "Not Covered: Call beneficios."
},
{
"settlementCode": "85",
"settlementDesc": ""
},
{
"settlementCode": "65",
"settlementDesc": ":"
}
];
function validateEntries (messages) {
if(!messages){ return [] };
const filteredMsg = messages.filter(mesg => {
if (checkString(mesg)) return mesg
} );
return filteredMsg;
};
const checkString = (mesg) => {
if (mesg.settlementDesc.indexOf(":") || mesg.settlementDesc.indexOf("")) {
return false;
} else {
return true;
}
};
validateEntries(messages);
ожидаемый результат
[
{
"settlementCode": "99",
"settlementDesc": "Not Covered: Call beneficios."
}
]