Как использовать JS Map Correlty ниже код выдаёт ошибку? - PullRequest
0 голосов
/ 30 мая 2019

не уверен, что если я что-то упускаю из-под кода, который выдает карту ошибок, это не функция?

Есть ли лучший подход к этому коду для достижения результатов?

main.js

const errorCodes = [99,890];
    const drug = [{
        "isBrand": true,
        "drugName": "Lipitor",
        "specialtyPrice": {}
      },
      {
        "isBrand": false,
        "drugName": "Atorvastatin Calcium",
        "drugStrength": "80mg",
        "drugForm": "Tablet",
        "mailPrice": {
          "totalQuantity": 90,
          "rejectMessage": [{
            "settlementCode": "99",
            "settlementDesc": "Sorry, the system is temporarily:Lo sentimos,Intente(Código de error 85)"
          }]
        },
        "retailPrice": {
          "totalQuantity": 30,
          "rejectMessage": [{
            "settlementCode": "99",
            "settlementDesc": "Sorry, the system is temporarily:Lo sentimos,Intente(Código de error 85)"
          }]
        },
        "specialtyPrice": {}
      }
    ];

          const filteredPrices = drug.map(item => {
            const errorCodes = drugPriceErrors;
            const pricePath = ['mailPrice.rejectMessage', 'retailPrice.rejectMessage'];

            _.forEach(pricePath, function (path)  {
              const rejectMsg = _.get(item, path);
              const hasCode = rejectMsg && rejectMsg.find(i => !!~errorCodes.indexOf(+i.settlementCode));
              hasCode && delete item[path.split('.').shift()];
            });

            return item;
          });

Ошибка:

TypeError: drug.map is not a function
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...