Can you improve this? Zipping two lists, the result must be same size as the first list

So I had a little time and reviewed again.

pair_with_recursion is @LostKobrakai’s code.

pair_with_tail_recursion is @derek-zhou’s code (amended slightly by @moogle19).

I have put pair_with_tail_recursion at the end – this didn’t change the order with which the benchmarks were being run (predictably, because the order with which you iterate through map’s pairs is not guaranteed in Elixir) but you (@adamu) are indeed correct that this tilted the benchmark slightly in favour of @derek-zhou’s code.

And now I remember why I left both in the module. @derek-zhou’s code uses Enum.reverse in the public function, at the end, while @LostKobrakai’s does so in the terminating condition in the private function. The difference should be inconsequential indeed as we’re seeing but I’ve learned not to presume anything and just measure so that’s why I left both variants intact.

But yep, seems they are identical so instead of proclaiming a single winner I say this:


@LostKobrakai and @derek-zhou practically arrived at the same solution with one super minor difference so they’re both winners. :bowing_man: (and kudos to @moogle19 for slightly improving upon the code)

1 Like