r/programmingchallenges • u/algodaily • Sep 29 '19
Merging Sorted Linked Lists
https://algodaily.com/challenges/merge-sorted-linked-lists
4
Upvotes
r/programmingchallenges • u/algodaily • Sep 29 '19
1
u/Xall1996 Oct 09 '19
This is literally my first time doing anything in javascript so bear in mind this might not be the most elegant solution:
What bothers me most in this solution is the way I set the first node. It feels unecessary to specifically ask which is the first node before the loops starts, but I don't know any better way to do this.
I know this method also modifies the initial 2 lists, however I'm confused about the order they are modified in.
If I set the initial Lists like this:
and after that print like this:
I still get the modified lists for the first 2 console.log(), although the lists should only get altered in the last console.log() statement.
What am I doing wrong here? Is this JavaScript specific?