Created
June 19, 2017 10:58
-
-
Save Kcko/c1e80cf7ba35c3f29e1d2f36fceafad4 to your computer and use it in GitHub Desktop.
MathUtils
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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