-3

I want to replace this filter and map using, with reduce:

      simpleFilter: fields
        .filter((f) => {
          const type = getUnifiedDataType(f.fieldType);
          return !type.isArray && ["text", "number"].includes(type.type);
        })
        .map((f) => ({
          name: f.fieldName,
          type: getUnifiedDataType(f.fieldType).type,
        })),
  • What did you try? Where did you got stuck? Please read [ask] and [tour]. Afterwards, [edit] your question to add a [mre]. – 0stone0 May 02 '22 at 14:25
  • Does this answer your question? [Main difference between map and reduce](https://stackoverflow.com/questions/49934992/main-difference-between-map-and-reduce) – Kenny May 02 '22 at 14:26

1 Answers1

0

it should be

simpleFilter: fields
  .reduce((res, f) => {
    const type = getUnifiedDataType(f.fieldType);
    if (!type.isArray && ["text", "number"].includes(type.type)) {
      res.push({
        name: f.fieldName,
        type: getUnifiedDataType(f.fieldType).type,
      })
    }
    return res;
  }, []);

R4ncid
  • 6,944
  • 1
  • 4
  • 18
  • 1
    I feel like answering a question that does not respect [How to ask](https://stackoverflow.com/help/how-to-ask) only encourages people to ask questions without even trying/giving enough context. – marius florescu May 02 '22 at 14:29