-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from shibisuriya/feat/tracks
Feat/tracks
- Loading branch information
Showing
11 changed files
with
206 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { NUMBER_OF_COLUMNS, NUMBER_OF_ROWS, DIRECTIONS } from './constants'; | ||
|
||
const isCellValid = (i, j) => { | ||
return !(i > NUMBER_OF_ROWS || j > NUMBER_OF_COLUMNS); | ||
}; | ||
|
||
const generateKey = (i, j) => { | ||
if (!isCellValid(i, j)) { | ||
throw new Error(`Invalid coordinates! ${i} ${j}`); | ||
} | ||
return `${i}-${j}`; | ||
}; | ||
|
||
const generateValue = (x, y) => { | ||
if (!isCellValid(x, y)) { | ||
throw new Error(`Invalid coordinates! ${i} ${j}`); | ||
} | ||
return { x, y }; | ||
}; | ||
|
||
const getOppositeDirection = (direction) => { | ||
switch (direction) { | ||
case DIRECTIONS.DOWN: | ||
return DIRECTIONS.UP; | ||
case DIRECTIONS.UP: | ||
return DIRECTIONS.DOWN; | ||
case DIRECTIONS.LEFT: | ||
return DIRECTIONS.RIGHT; | ||
case DIRECTIONS.RIGHT: | ||
return DIRECTIONS.LEFT; | ||
default: | ||
throw new Error(`Invalid direction, ${direction}.`); | ||
} | ||
}; | ||
|
||
export { getOppositeDirection, generateValue, generateKey, isCellValid }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.