I'm trying to understand what is going on with the second map here.

Hey all! I'm currently trying to work through this kata in Javascript which is pretty low level. I'm trying to understand what is going on with the second map here. Would someone mind explaining to me why this solution works and if there is a better way of going about it?
Here is a link to my code:
https://repl.it/repls/ShabbyTerribleRobot
Any help is appreciated.
Thanks in advance!
You already invited:

Roman

Upvotes from:

first of all, you shouldn't be using map. if you want to do side-effects, use forEach, for or for ... of
the logic inside the else block is totally bad, you get the correct result only by coincidence
If you were to switch those inner-arrays around you would miss some of the destinations
 

If you wanna answer this question please Login or Register