Skip to content

Code simplification, removed duplication #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chrisatomix
Copy link

This plugin helped me a lot (thanks!), however I noticed most of the code was being repeated so I spent 15 minutes trying to simplify it. It seems to be working correctly, currency sorting works fine & fast on a table with 500 rows (built using a JS array).
Reduced from 47 lines to 32 lines.

You could probably even reduce it further like so:

$.extend( $.fn.dataTableExt.oSort, {
    "currency-asc" : function (a, b) {
        'use strict';
        return cleanCurrency(a) - cleanCurrency(b);
    },
    "currency-desc" : function (a, b) {
        'use strict';
        return cleanCurrency(b) - cleanCurrency(a);
    }
});

This gets it down to 28 lines, but it's fairly trivial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant