Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
MathUtils
(function($) {
$.mathUtils = {
sum: function(array) {
var total = 0;
$.each(array, function(index, value) {
total += $.mathUtils.parseCzechFloat(value);
});
return total;
},
parseCzechFloat: function(string) {
var value = $.trim(string);
return parseFloat(value.replace(' ', '').replace(',', '.')) || 0;
},
formatCzechFloat: function(number) {
return String(number).replace('.', ',');
},
average: function(array) {
if ($.isArray(array)) {
return $.mathUtils.sum(array) / array.length;
}
return '';
}
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment