地图和深物体与兰姆达

 收藏

我需要按“细分”属性进行过滤,在这种情况下,我需要按细分进行过滤:[名称:“常规”

我有以下数组

const lines = [
      {
        0: {
          id: 1191,
          name: "dev",
          segments: []
        },
      },
      {
        0: {
          id: 1192,
          name: "credit",
          folder: "Embarazadas",
          segments: [
            {
              "name": "general",
            },
            {
              "name": "custom",
            }
          ]
        },
      },

      {
        0: {
          id: 1311,
          name: "box",
          segments: [
            {
              "name": "custom",
              "line_id": 1431,
              "id": 21,
              "active": true
            }
          ]
        },
      {
        id: 2000,
        name: "sin folder",
        folder: null,
        segments: [
          {
            "name": "custom",
          },
{
            "name": "general",
          }
        ],
      },
      {
        id: 2000,
        name: "credit card",
        segments: [
          {
            "name": "general",
          }
        ],
      },

    ]

我需要获取所有具有“常规”段的对象

我尝试了Ramda这样做,但是我没有得到结果,首先我绘制了线条图,然后进行了过滤。 问题在于,细分属性有时会变为空

const filterLinesBySegments = (lines) => {
  const filter = (line) => {
    const hasSegments =R.filter(seg => seg["name"] === "general")(line.segments)
    const newLine = R.compose(
      R.assoc("segments", hasSegments),
    )(line)
    return newLine

  }
  const new= R.map(item => {
      return R.filter(line => {
        return filter(line)
      })(item)

  })(lines)

  return new;
}   
回复