Trying to incorporate metadata to hist bins

Incomplete incorporation of metadata with histogram bins. Something
wrong with my logic here. Attempting to find the indices of the age
data FROM each bins. Then I am trying to use those indices for the
gender attribute of the data to calculate % male and % female for each
bin. Not working! I am sure logic is wrong here. Should be able to
access that data directly from svg + histogram layout?