FACxBeamery / antonio-project-week-6

0 stars 0 forks source link

Aim for human readable code #13

Open arrested-developer opened 5 years ago

arrested-developer commented 5 years ago

https://github.com/FACxBeamery/antonio-project-week-6/blob/ef49f343a2046978d628aed6ff19132fb2723ff5/antonio-week-6/src/components/board/grid.js#L5-L13

This function is written using very imperative code - try to rewrite it to be more human readable. After reading over this again I have just recognised that you've used recursion. Nice! But can you find a way to make the code explain better to others (and to your future self) what it actually does?

Some suggestions:

AntonioGargaro commented 5 years ago

For your second point, dimensions[0] is not an array, rather just a number being accessed at index 0 of the array. I'm not sure of a better iterator than a for loop, except maybe a while loop? What is your thoughts on for loops vs. while loops?

arrested-developer commented 5 years ago

Oh, my mistake. Well I guess this goes to show how difficult it is to read your function 😉

What are you iterating through with the for loop? Could you use an array method instead?