Skip to content
Advertisement

How can I make my list print its elements in a fashioned order?

I currently have a populated list full of nodes in a path from one node to another. I need to stylize the printing of the path as such:

JavaScript

I currently have this code to do so:

JavaScript

But the path is not being printed. The path list is populated, but the program does not give any output.

What do I need to change in order for this path to print?

Advertisement

Answer

It looks like you want to print each element in the path with ” -> ” between them.

JavaScript

should print them that way.

If you want a ” -> ” on the end too, just add one on the end in the print statement

JavaScript

so a path of ["a", "b", "c"] will print a -> b -> c ->

If you want it to break on multiples of 4 nodes you can break the array into chunks of 4 first

JavaScript

which will print

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement