This repository has been archived by the owner on Sep 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ray Foo
committed
Aug 26, 2022
1 parent
04a06f6
commit a7d4f5f
Showing
3 changed files
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@busyxiang/utilities-js': patch | ||
--- | ||
|
||
Add number average util |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { average } from './number'; | ||
|
||
describe('average', () => { | ||
test('it should return average value', () => { | ||
const aver = average(1, 2, 3); | ||
|
||
expect(aver).toBe(2); | ||
}); | ||
|
||
test('it should return average value(spread array)', () => { | ||
const aver = average(...[1, 2, 3]); | ||
|
||
expect(aver).toBe(2); | ||
}); | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const average = (...nums: number[]) => { | ||
return nums.reduce((acc, value) => acc + value, 0) / nums.length; | ||
}; |