1

I'm trying to remove an object from an array of objects if a certain value exists in nested data.

The data being returned from the API is shaped like this:

Array [
  Object {
    "id": "/db/Shifts/123",
    "applicants": Object {
      "applicants": Array [
        "/db/User/12",
        "/db/User/13",
      ],
  },
  Object {
    "id": "/db/Shifts/456",
    "applicants": Object {
      "applicants": Array [
        "/db/User/12",
        "/db/User/14",
      ],
  },  
  Object {
    "id": "/db/Shifts/789",
    "applicants": Object {
      "applicants": Array [
        "/db/User/13",
        "/db/User/14",
      ],
  },
]

Using Ramda, how would I filter out the shifts where User 12 exists in the array of applicants, which would be located at applicants.applicants.

I am not able to flatten the data in this case, the list of applicants for each shift does have to be an array contained in an object.

I tried this:

var hasApplied = pathEq(['applicants', 'applicants'], 'db/User/12');
console.log(filter(hasApplied, shifts));

But I don't think that is quite right because applicants.applicants is an array, I feed like I need to be feeding it one more function to get into the array of applicants but I'm not sure what.

1 Answer 1

2

Your use of R.pathEq is resulting in the user ID being compared with each array of IDs for equality, rather than checking whether each array contains the given ID.

You could instead make use of R.pathSatisfies along with R.contains

const hasApplied = R.pathSatisfies(R.contains('/db/User/12'), ['applicants', 'applicants'])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.