Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
700ae637
Commit
700ae637
authored
Mar 01, 2019
by
Filipa Lacerda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moves utility function into CE
parent
31353188
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
0 deletions
+35
-0
app/assets/javascripts/lib/utils/number_utils.js
app/assets/javascripts/lib/utils/number_utils.js
+19
-0
changelogs/unreleased/10097-number-utils.yml
changelogs/unreleased/10097-number-utils.yml
+5
-0
spec/javascripts/lib/utils/number_utility_spec.js
spec/javascripts/lib/utils/number_utility_spec.js
+11
-0
No files found.
app/assets/javascripts/lib/utils/number_utils.js
View file @
700ae637
...
...
@@ -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
;
changelogs/unreleased/10097-number-utils.yml
0 → 100644
View file @
700ae637
---
title
:
Moves EE util into the CE file
merge_request
:
25680
author
:
type
:
other
spec/javascripts/lib/utils/number_utility_spec.js
View file @
700ae637
...
...
@@ -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
);
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment