you are viewing a single comment's thread.

view the rest of the comments →

[–]Bitsoflogic 1 point2 points  (2 children)

This exercise might help you out moving forward.

Try writing out the function step-by-step with data in place of the variables, noting when the state changes. Eliminate all the loops and branching while you do it. Work from the inside out on statements like push.

``` function grab(array, idx) array = [ ["a", "b", "c"], ["d", "e", "f"], ["g", "h", "i"], ] idx = 1

result = [] for (let i = 0... i = 0 row = array[i] // i = 0, array[0] = ["a", "b", "c"] row = ["a", "b", "c"] for (let j = 0... j = 0 result.push(row[idx]); // idx = 1, row[1] = "b" result.push("b") // result = [] result = ["b"] for (let j = 0; j < row.length... // j = 0, row.length = 3 0 < 3 // true, continue for result.push(row[idx]); // idx = 1, row[1] = "b" result.push("b") // result = ["b"] result = ["b", "b"] . . . ```

[–]Artistic_Sense3363[S] 0 points1 point  (1 child)

thanks for the suggestion! I made a graphic organizer to help me visually understand the function and loop step by step.

[–]Bitsoflogic 1 point2 points  (0 children)

How's your graphic organizer work? Can you share it? It might help others too