Modernizing JavaScript Code: The Comparator Function