Skip to content

Instantly share code, notes, and snippets.

@Kcko
Created June 19, 2017 10:58
Show Gist options
  • Select an option

  • Save Kcko/c1e80cf7ba35c3f29e1d2f36fceafad4 to your computer and use it in GitHub Desktop.

Select an option

Save Kcko/c1e80cf7ba35c3f29e1d2f36fceafad4 to your computer and use it in GitHub Desktop.
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