Demonstrating how two algorithms of the same number of line can be striking different in terms of performance.
I tested both algorithm on repl.it and used the same values for both tests.
The second algorithm:
30313411: true
Time taken: 435ms
The first algorithm:
30313411: true
Time taken: 11ms
You can test for yourself on repl.it using the follow links: