summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2019-03-01 14:44:54 +0000
committerPhil Hughes <me@iamphill.com>2019-03-01 14:44:54 +0000
commit4471ab81c8484d9942183bd8114a757b8630b8ec (patch)
tree13bd74742b23175aa3f9bfd32638c62c39a80698
parent8c2a5b75d27d3f6e0124c763eac2690116332ff5 (diff)
parent700ae637d20a4c4f5754046e0f3a7bdb8931358b (diff)
downloadgitlab-ce-4471ab81c8484d9942183bd8114a757b8630b8ec.tar.gz
Merge branch '10097-number-utils' into 'master'
Moves EE differences out of number_utils.js Closes gitlab-ee#10097 See merge request gitlab-org/gitlab-ce!25680
-rw-r--r--app/assets/javascripts/lib/utils/number_utils.js19
-rw-r--r--changelogs/unreleased/10097-number-utils.yml5
-rw-r--r--spec/javascripts/lib/utils/number_utility_spec.js11
3 files changed, 35 insertions, 0 deletions
diff --git a/app/assets/javascripts/lib/utils/number_utils.js b/app/assets/javascripts/lib/utils/number_utils.js
index 2ccc51c35f7..19c4de6083d 100644
--- a/app/assets/javascripts/lib/utils/number_utils.js
+++ b/app/assets/javascripts/lib/utils/number_utils.js
@@ -80,3 +80,22 @@ export function numberToHumanSize(size) {
}
return `${bytesToGiB(size).toFixed(2)} GiB`;
}
+
+/**
+ * A simple method that returns the value of a + b
+ * It seems unessesary, but when combined with a reducer it
+ * adds up all the values in an array.
+ *
+ * e.g. `[1, 2, 3, 4, 5].reduce(sum) // => 15`
+ *
+ * @param {Float} a
+ * @param {Float} b
+ * @example
+ * // return 15
+ * [1, 2, 3, 4, 5].reduce(sum);
+ *
+ * // returns 6
+ * Object.values([{a: 1, b: 2, c: 3].reduce(sum);
+ * @returns {Float} The summed value
+ */
+export const sum = (a = 0, b = 0) => a + b;
diff --git a/changelogs/unreleased/10097-number-utils.yml b/changelogs/unreleased/10097-number-utils.yml
new file mode 100644
index 00000000000..417008f6539
--- /dev/null
+++ b/changelogs/unreleased/10097-number-utils.yml
@@ -0,0 +1,5 @@
+---
+title: Moves EE util into the CE file
+merge_request: 25680
+author:
+type: other
diff --git a/spec/javascripts/lib/utils/number_utility_spec.js b/spec/javascripts/lib/utils/number_utility_spec.js
index 94c6214c86a..818404bad81 100644
--- a/spec/javascripts/lib/utils/number_utility_spec.js
+++ b/spec/javascripts/lib/utils/number_utility_spec.js
@@ -4,6 +4,7 @@ import {
bytesToMiB,
bytesToGiB,
numberToHumanSize,
+ sum,
} from '~/lib/utils/number_utils';
describe('Number Utils', () => {
@@ -87,4 +88,14 @@ describe('Number Utils', () => {
expect(numberToHumanSize(10737418240)).toEqual('10.00 GiB');
});
});
+
+ describe('sum', () => {
+ it('should add up two values', () => {
+ expect(sum(1, 2)).toEqual(3);
+ });
+
+ it('should add up all the values in an array when passed to a reducer', () => {
+ expect([1, 2, 3, 4, 5].reduce(sum)).toEqual(15);
+ });
+ });
});