Array size 114467 good, 114468 not work
<p>I have a strange problem with my alghoritm, which work if array size less than 114468 and doesn't work if more than 114468. Browse with google chrome. Can't understand why =\ Here is the code:</p>

<p><strong>Generate array:</strong></p>

<pre><code>    var arr = [];
    var res = [];
    for (var i = 114467; i &gt; 0; i--) {
        arr.push([i - 1, i]);
    }
</code></pre>

<p><strong>Find first elem in array to sort:</strong></p>

<pre><code>        for (var i = 0, j = arr.length; i &lt; j &amp;&amp; res.length == 0; i++) {
            var found = false;
            for (var m = 0; m &lt; j; m++) {
                if (i == m || arr[i][0] == arr[m][1] || arr[i][1] == arr[m][0]) {
                    found = true;
                    break;
                }

                if (!found) {
                    res.push(arr[m]);
                    arr.splice(m, 1);
                }
            }
        }
</code></pre>

<p><strong>Sorting:</strong></p>

<pre><code>        do {
            for (var i = 0, j = arr.length; i &lt; j; i++) {
                var resLength = res.length - 1;
                if (arr[i][1] == res[resLength][0] || arr[i][0] == res[resLength][1]) {
                    res.push(arr[i]);
                    arr.splice(i, 1);
                    break;
                }
            }
        } while (arr.length &gt; 0);
</code></pre>

<p>On the step sorting it stops to work.</p>

<p>All code:</p>

<pre><code>var t = function () {
    var arr = [];
    var res = [];
    for (var i = 114467; i &gt; 0; i--) {
        arr.push([i - 1, i]);
    }

    var startsec = new Date().getSeconds();
    var startmilsec = new Date().getMilliseconds();
    document.write(startsec + '.' + startmilsec + '&lt;br&gt;');

    for (var i = 0, j = arr.length; i &lt; j &amp;&amp; res.length == 0; i++) {
        var found = false;
        for (var m = 0; m &lt; j; m++) {
            if (i == m || arr[i][0] == arr[m][1] || arr[i][1] == arr[m][0]) {
                found = true;
                break;
            }

            if (!found) {
                res.push(arr[m]);
                arr.splice(m, 1);
            }
        }
    }

    do {
        for (var i = 0, j = arr.length; i &lt; j; i++) {
            var resLength = res.length - 1;
            if (arr[i][1] == res[resLength][0] || arr[i][0] == res[resLength][1]) {
                res.push(arr[i]);
                arr.splice(i, 1);
                break;
            }
        }
    } while (arr.length &gt; 0);

    var stopsec = new Date().getSeconds();
    var stopmilsec = new Date().getMilliseconds();
    document.write(stopsec + '.' + stopmilsec + '&lt;br&gt;');
    var executionTime = (stopsec - startsec).toString() + "s" + (stopmilsec - startmilsec).toString() + "'ms";
    document.write(executionTime + '&lt;br&gt;');
} ();
</code></pre>

<p>Do i get my memory limit?</p>
