FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScript/Maths/AverageMedian.js at master · MMABSOUT/JavaScript · GitHub
MMABSOUT
/
JavaScript
Public
forked from
TheAlgorithms/JavaScript
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScript
/
Maths
/
AverageMedian.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
22 lines (18 loc) · 799 Bytes
Breadcrumbs
JavaScript
/
Maths
/
AverageMedian.js
Copy path
File metadata and controls
22 lines (18 loc) · 799 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*
* Median: https://en.wikipedia.org/wiki/Median
*
* function averageMedian
* to find the median value of an array of numbers
* the numbers in an array will be sorted in ascending order by the function sortNumbers
* if the length of the array is even number, the median value will be the average of the two middle numbers
* else if the length of the array is odd number, the median value will be the middle number in the array
*/
const
averageMedian
=
(
sourceArrayOfNumbers
)
=>
{
const
numbers
=
[
...
sourceArrayOfNumbers
]
.
sort
(
sortNumbers
)
const
numLength
=
numbers
.
length
return
numLength
%
2
===
0
?
(
numbers
[
numLength
/
2
-
1
]
+
numbers
[
numLength
/
2
]
)
/
2
:
numbers
[
Math
.
floor
(
numLength
/
2
)
]
}
const
sortNumbers
=
(
num1
,
num2
)
=>
num1
-
num2
export
{
averageMedian
}
Back
|
FazBrowse Home
|
New Git URL