mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-07 02:05:08 +08:00
Update AverageMedian.js and AverageMedian.test.js
This commit is contained in:
@ -8,7 +8,7 @@
|
|||||||
* else if the length of the array is odd number, the median value will be the middle number in the array
|
* else if the length of the array is odd number, the median value will be the middle number in the array
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Doctests
|
* Doctests
|
||||||
*
|
*
|
||||||
* > averageMedian([8, 9, 1, 2, 5, 10, 11])
|
* > averageMedian([8, 9, 1, 2, 5, 10, 11])
|
||||||
@ -20,7 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const averageMedian = (numbers) => {
|
const averageMedian = (numbers) => {
|
||||||
let median = 0, numLength = numbers.length
|
let median = 0; const numLength = numbers.length
|
||||||
numbers = numbers.sort(sortNumbers)
|
numbers = numbers.sort(sortNumbers)
|
||||||
|
|
||||||
if (numLength % 2 === 0) {
|
if (numLength % 2 === 0) {
|
||||||
|
@ -16,6 +16,6 @@ test('should return the median of an array of numbers:', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
test('should return the median of an array of numbers:', () => {
|
test('should return the median of an array of numbers:', () => {
|
||||||
const medianValue = averageMedian([1,2,3,4,6,8])
|
const medianValue = averageMedian([1, 2, 3, 4, 6, 8])
|
||||||
expect(medianValue).toBe(3.5)
|
expect(medianValue).toBe(3.5)
|
||||||
})
|
})
|
Reference in New Issue
Block a user