I'll give some hints. Severities is an array that has 6 elements [0, 0, 0, 0, 0, 0] to hold how many wounds of each severity there are. In JS all arrays start at index = 0, so i created an extra element and ignored 0. This made some of the later work easier. So if you have 3 wound of severity 1, and 1 of severity 3, this will have value [0, 3, 0, 1, 0, 0] sevmins holds the minimum point on the threshold track for each of the wound types. again I had to include an element 0, but its ignored. This code populates the severities array: if ([ 1 , 2 , 3 , 4 , 5 ]. includes ( sev )) { severities [ sev ] = severities [ sev ] + 1 ; The first line is probably unnecessary but it does no harm. It checks that the severity of this wound is a valid value. If so it adds 1 to the value at the the index matching the current wound size. So if its a light wound, sev = 1. And therefore severities[1] gets increased by 1, since severities[1] holds the number of light wounds you've found. This line is a compact function: const findNextEmptyWound = ( arr , start ) => arr . indexOf ( '0' , start ); It is called from within the reduce function that follows, which will pass the current value of the health track, which starts like this ['0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'], and a starting value to search from (this is based on wound size). It will return the first 0 value it finds from that starting point. So if you take a light wound, it will return 1, since it starts searching from position 1, and there's a zero value right there. But if you already have 3 light wounds, the health track will look like ['0', '1', '1', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0'], and so the function will start looking from index 1, and find the first '0' value at index 4. That allows the reduce function to mark the correct position on the wound track. So the reduce function basically takes the severities array (which you'll recall with look something like [0, 3, 0, 1, 0, 0]) and steps through each index. Then at that index, it will see how many wounds there are and for each of them, will use the findNextEmptyWound function to mark the positions on the health track that need wounds. It then returns an array which might look like ['0', '1', '1', '1', '0', '0', '0', '0', '1', '0', '0', '0', '0']. then moving down to healthtrack.foreach, that steps through the above array, and assigns a value of 0 or 1 to each of the attributes health1, health2, etc. these are saved in the output function, so we dont have to call setAttrs multiple times. Finally setAttrs saves all the updated attribute values to the character sheet in one move. Hope this helps your understanding.