How to reverse a function

How to reverse a function

Working on a point system that assigns points for every element with matching content in a group of search results. It works well when I compare the contents from .per-results to .myself, but it doesn't work when I do the comparison from .myself to .per-result.

When reversed, it still assigns points but it assigns the same amount of points for all .per-resultwhen it should differ. My code looks like below.


$(function() { $('.per-result').each(function() { var $matches = $('span', this).filter(function() { // Each item var texts = $(this).text(); return $('.myself span').filter(function() { // Are there matches in .three? return $(this).text() === texts; }).length > 0; }).length; $('.theyRate', this).text(('They score me ' + $matches * 6 + ' Points' )); }); //Reversing the point system var $matches = $('.myself span', this).filter(function() { // Each item var texts = $(this).text(); return $('.per-result span').filter(function() { // Are there matches in .three? return $(this).text() === texts; }).length > 0; }).length; $('.iRate').text(('I score them ' + $matches * 6 + ' Points' )); });

Link to the fiddle