Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
Lines changed: 17 additions & 0 deletions
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‎

Lines changed: 0 additions & 17 deletions
This file was deleted.

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

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
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‎

Lines changed: 2 additions & 2 deletions
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‎

Lines changed: 1 addition & 1 deletion
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)

AltStyle によって変換されたページ (->オリジナル) /