First you check for black matches, then white matches using only those positions that didn't get a black match.
Checking for black matches is simple. If position i in the guess matches position i in the code, it's a match. Then eliminate i from the list of positions that will be used for checking white matches.
Then, for each colour of peg, count the number of pegs of that colour in the guess, and in the code. (using only the positions that haven't been eliminated in the previous step) For each colour, pick the smaller count of either the guess or of the code, and add them all up. That will be the number of white matches.
Does this make sense?