Skip to content

Commit b71a2eb

Browse files
committed
Change naming for Jump Game files.
1 parent df17e29 commit b71a2eb

File tree

6 files changed

+37
-37
lines changed

6 files changed

+37
-37
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import backtrackingJumpGame from '../backtrackingJumpGame';
2+
3+
describe('backtrackingJumpGame', () => {
4+
it('should solve Jump Game problem in backtracking manner', () => {
5+
expect(backtrackingJumpGame([1, 0])).toBeTruthy();
6+
expect(backtrackingJumpGame([100, 0])).toBeTruthy();
7+
expect(backtrackingJumpGame([2, 3, 1, 1, 4])).toBeTruthy();
8+
expect(backtrackingJumpGame([1, 1, 1, 1, 1])).toBeTruthy();
9+
expect(backtrackingJumpGame([1, 1, 1, 10, 1])).toBeTruthy();
10+
expect(backtrackingJumpGame([1, 5, 2, 1, 0, 2, 0])).toBeTruthy();
11+
12+
expect(backtrackingJumpGame([1, 0, 1])).toBeFalsy();
13+
expect(backtrackingJumpGame([3, 2, 1, 0, 4])).toBeFalsy();
14+
expect(backtrackingJumpGame([0, 0, 0, 0, 0])).toBeFalsy();
15+
expect(backtrackingJumpGame([5, 4, 3, 2, 1, 0, 0])).toBeFalsy();
16+
});
17+
});

src/algorithms/uncategorized/jump-game/__test__/btJumpGame.test.js

-17
This file was deleted.

src/algorithms/uncategorized/jump-game/__test__/grdJumpGame.test.js

-17
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import greedyJumpGame from '../greedyJumpGame';
2+
3+
describe('greedyJumpGame', () => {
4+
it('should solve Jump Game problem in greedy manner', () => {
5+
expect(greedyJumpGame([1, 0])).toBeTruthy();
6+
expect(greedyJumpGame([100, 0])).toBeTruthy();
7+
expect(greedyJumpGame([2, 3, 1, 1, 4])).toBeTruthy();
8+
expect(greedyJumpGame([1, 1, 1, 1, 1])).toBeTruthy();
9+
expect(greedyJumpGame([1, 1, 1, 10, 1])).toBeTruthy();
10+
expect(greedyJumpGame([1, 5, 2, 1, 0, 2, 0])).toBeTruthy();
11+
12+
expect(greedyJumpGame([1, 0, 1])).toBeFalsy();
13+
expect(greedyJumpGame([3, 2, 1, 0, 4])).toBeFalsy();
14+
expect(greedyJumpGame([0, 0, 0, 0, 0])).toBeFalsy();
15+
expect(greedyJumpGame([5, 4, 3, 2, 1, 0, 0])).toBeFalsy();
16+
});
17+
});

src/algorithms/uncategorized/jump-game/btJumpGame.js renamed to src/algorithms/uncategorized/jump-game/backtrackingJumpGame.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @param {number[]} currentJumps - current jumps path.
77
* @return {boolean}
88
*/
9-
export default function btJumpGame(numbers, startIndex = 0, currentJumps = []) {
9+
export default function backtrackingJumpGame(numbers, startIndex = 0, currentJumps = []) {
1010
if (startIndex === numbers.length - 1) {
1111
// We've jumped directly to last cell. This situation is a solution.
1212
return true;
@@ -26,7 +26,7 @@ export default function btJumpGame(numbers, startIndex = 0, currentJumps = []) {
2626
const nextIndex = startIndex + jumpLength;
2727
currentJumps.push(nextIndex);
2828

29-
const isJumpSuccessful = btJumpGame(numbers, nextIndex, currentJumps);
29+
const isJumpSuccessful = backtrackingJumpGame(numbers, nextIndex, currentJumps);
3030

3131
// Check if current jump was successful.
3232
if (isJumpSuccessful) {

src/algorithms/uncategorized/jump-game/grdJumpGame.js renamed to src/algorithms/uncategorized/jump-game/greedyJumpGame.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @param {number[]} numbers - array of possible jump length.
55
* @return {boolean}
66
*/
7-
export default function grdJumpGame(numbers) {
7+
export default function greedyJumpGame(numbers) {
88
// The "good" cell is a cell from which we may jump to the last cell of the numbers array.
99

1010
// The last cell in numbers array is for sure the "good" one since it is our goal to reach.

0 commit comments

Comments
 (0)