How to fInd the index from which distance of every requirements are closest to the Index

let blocks = [
  {
    gym:false,
    school:true,
    store:false,
  },
  {
    gym:true,
    school:false,
    store:false,
  },
  {
    gym:true,// and this contains gym
    school:true,
    store:false,
  },
  {
    gym:false,
    school:true,  // this block is the answer as I can find all three requirements near to this index above and below index; 
    store:false,
  },
  {
    gym:false,
    school:true, // this contains store
    store:true,
  }
]

let filter = ['school','gym','store'];

Eg. Here the correct index is 3 as 2,3,4 index fulfilled all the requirements element. We could have n number of requirements and n number of elements.

Source: Ask Javascript Questions

LEAVE A COMMENT