Hi @kernix and sorry for my delayed reply. Im glad you find my solution helpful and you try to fit in your project. @colinthornton guided you very well into how you can apply the solution in your project.
Your data is already in the form of array of objects, you need not do any specific adjustments. You want to access the steps
array in every object, to compare it to an array the user inputs and return the one which matches. This is why i use the array find
method. It would sift throught your json data(presumable array of objects) and return the one which matches our criteria. The compareArrays
function is the criteria, which we provide indirectly as a callback to the find method. Only if it returns true(we found matching steps
), it would return the object.
Basically the arrOfObjects
variable in my code, represents your json data. The arrWeLookFor
represents the user input array. When we call compareArrays
, we provide two arrays as a parameter, the array we want to match and the current steps
array we compare. In order for the code to work in your case, you will need to change the arr
parameter with the name of the object property we destructure(steps
). Ofc, you could use different approach from destructuring, if you find it confusing.
This is how it might look in your case:
const result=arrOfObjects.find(({steps})=>{
return compareArrays(steps, arrWeLookFor)
})
// OR
const result=arrOfObjects.find((obj)=>{
return compareArrays(obj.steps, arrWeLookFor)
})
With some adjustments we could even go step further and provide the compareArrays directly as callback to find, but this might make the code less intuitive to understand.