Skip to content

Commit 73efc89

Browse files
authored
merge: Fix GnomeSort algorithm and Add test case to it (#948)
1 parent 532cf3e commit 73efc89

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

Sorts/GnomeSort.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export function gnomeSort (items) {
1919
i = Math.max(1, i - 1)
2020
}
2121
}
22+
return items
2223
}
2324

2425
// Implementation of gnomeSort

Sorts/test/GnomeSort.test.js

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