Conversation
src/components/Main/check.js
Outdated
| // check that all zebra colors are different | ||
| const checkZebras = (zebraColors) => (new Set(zebraColors)).size === zebraColors.length; | ||
|
|
||
| // check that all leopard colors are the same as the background | ||
| const checkLeopards = (leopardColors, backgroundColor) => leopardColors.every((e) => e === backgroundColor) | ||
|
|
||
| // check that all plant colors are rgb(48, 98, 48) | ||
| const checkPlants = (plantColors) => plantColors.every((e) => e === "rgb(48, 98, 48)") | ||
|
|
There was a problem hiding this comment.
are all zebras supposed to be different colors always? so are all animals supposed to be a certain way regardless of level?
There was a problem hiding this comment.
yes! and all the levels should be designed with those rules in mind
timothycpoon
left a comment
There was a problem hiding this comment.
Mostly seems good, just a couple comments
| @@ -1,17928 +1,8 @@ | |||
| { | |||
| "name": "teach-la-react-starter-barebones", | |||
| "version": "0.1.0", | |||
| "lockfileVersion": 2, | |||
There was a problem hiding this comment.
You should probably stick to newer versions of NPM
There was a problem hiding this comment.
okay i updated it
src/components/Main/check.js
Outdated
|
|
||
| const check = (boardEl, setStickerStyles, backgroundColor) => { | ||
| let stickerStyles = {}; | ||
| let zebraColors = []; //for plant colors test to work an element will need to be added to this array |
There was a problem hiding this comment.
Depending on how much you foresee extending this, consider having a map of arrays instead of adding an array for each new entity.
|
I added a |
|
|
||
| const check = (boardEl, setStickerStyles, backgroundColor) => { | ||
| let stickerStyles = {}; | ||
| let colorsToCheck = checks.map(() => []); |
There was a problem hiding this comment.
Sorry if I was unclear; when I mentioned map I meant like
{
zebra: [],
leopard: [],
zebra: []
}
There was a problem hiding this comment.
i see i just thought this would be better. should i change it back and just use that?
There was a problem hiding this comment.
This method works fine, it just might be a bit more confusing when you're debugging the state, and just see an array of arrays.
| } | ||
| }); | ||
| stickerStyles[curNode.id] = stickerColor; | ||
| setStickerStyles(stickerStyles); |
There was a problem hiding this comment.
You shouldn't need to update the state on every iteration
| { | ||
| type: "tagName", | ||
| value: "LEOPARD", | ||
| check: (leopardColors, backgroundColor) => leopardColors.every((e) => e === backgroundColor) |
There was a problem hiding this comment.
Instead of passing in backgroundColor as the second input, some sort of options object would be better, so that the number of arguments wouldn't keep rising as new animals are added.
|
|
||
| const check = (boardEl, setStickerStyles, backgroundColor) => { | ||
| let stickerStyles = {}; | ||
| let colorsToCheck = checks.map(() => []); |
There was a problem hiding this comment.
This method works fine, it just might be a bit more confusing when you're debugging the state, and just see an array of arrays.
| return colorsToCheck.every((colors, i) => checks[i].check(colors, backgroundColor)); | ||
| } | ||
|
|
||
| export default check; No newline at end of file |
There was a problem hiding this comment.
Having a newline at the end of files is a good convention to keep
| value: "plant", | ||
| check: (plantColors, _) => plantColors.every((e) => e === "rgb(48, 98, 48)") | ||
| } | ||
| ]; No newline at end of file |
There was a problem hiding this comment.
Same thing w/ newline
No description provided.