Skip to content

Commit d47555b

Browse files
authored
merge: Add test case and fix HeapSort Algorithm (TheAlgorithms#969)
1 parent c21ad2c commit d47555b

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Sorts/HeapSortV2.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ export function heapSort (input) {
3838

3939
heapRoot(input, 0)
4040
}
41+
return input
4142
}

Sorts/test/HeapSortV2.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { heapSort } from '../HeapSortV2'
2+
3+
test('The heapSort of the array [4, 3, 2, 1] is [1, 2, 3, 4]', () => {
4+
const arr = [4, 3, 2, 1]
5+
const res = heapSort(arr)
6+
expect(res).toEqual([1, 2, 3, 4])
7+
})
8+
9+
test('The heapSort of the array [] is []', () => {
10+
const arr = []
11+
const res = heapSort(arr)
12+
expect(res).toEqual([])
13+
})
14+
15+
test('The heapSort of the array [41, 31, 32, 31] is [31, 31, 32, 41]', () => {
16+
const arr = [41, 31, 32, 31]
17+
const res = heapSort(arr)
18+
expect(res).toEqual([31, 31, 32, 41])
19+
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy