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: 435msThe first algorithm:
30313411: true
Time taken: 11msYou can test for yourself on repl.it using the follow links: