 <p>Well, in <code>combineTours</code> function you're calling <code>.pop()</code> method on one array and <code>.shift()</code> method on another, which removes one element from each of these arrays. In <code>calculateAllSavings</code> you're calling <code>calculateSaving</code> in a loop and it's calling <code>combineTours</code>, so you're effectively removing all elements from the sub-arrays.</p> <p>Maybe you should just remove these lines from <code>combineTours</code>:</p> <pre><code>tourA.pop(); tourB.shift(); </code></pre> <p>For the future: use <a href="https://developer.mozilla.org/en/docs/Web/API/Console/log" rel="nofollow"><code>console.log()</code></a> for debugging, it could help you identify the issue.</p>