need to implement my algorithm using javascript
<p>I have made small algorithm and want to implement it using javascript. Here is my algorithm</p>

<p>I have a data in <code>data.json</code> file in this format</p>

<pre><code>[
"109 200",
"109 201",
"102 202",
"103 202"
]
</code></pre>

<p>What I am trying to do is</p>

<ol>
<li>Create four array containers i.e. c1, c2, c3 and c4.</li>
<li>Put above data in c1 container as it is</li>
<li><p>loop through c1 and put the data in c4 in following format</p>

<pre><code>"109",
"200",
"109",
"201",
"102",
"202",
"103",
"202"
</code></pre></li>
<li><p>loop through c1 and put them in c2 in this format</p>

<pre><code>"109,200"
</code></pre></li>
<li><p>then check if c3 is empty then read first value from c2 and push it in c3.</p></li>
<li><p>repeat step 4 but this time put second data i.e. "109 201" from c1 in c2 in this format</p>

<pre><code>"109,201"
</code></pre></li>
<li><p>then check if c3 is not empty then loop through c2 and check if any of these two values are repeated in c4. If it is repeated then repeat step 6 and 7 until it finds least amount of numbers from data.json.</p></li>
</ol>

<p>This algorithm is not efficient but still I want to use this.</p>

<p>Here is my code.</p>

<pre><code>var teams = [],
    c1 = [], arr = [], left = [], right = [], j = 0,
    show = function () {
        var span = $('#list');

        $.getJSON('data/data.json', function (ids) {

            //c1.push(c);
            for (var i = 0; i &lt; ids.length; i++) {
                var a = smallcontainer(ids);
                var b = bigcontainer(ids);
                var c;

                if (c1 == "") {
                    c = a[0].split(" ");
                    console.log(c);
                } else {

                }


                //console.log(c);
                var id = ids[i];
                teams = id;
                $('&lt;li&gt;' + id + '&lt;/li&gt;').appendTo(span);
            }
        });
    },

    smallcontainer = function (teams) { //arr
        arr = [teams[j]];
        j++;
        return arr;
    },

    bigcontainer = function (ids) { //c3. in code it is left+right=result
        for (var i = 0; i &lt; ids.length; i++) {
            var splitted = ids[i].split(" ");
            left.push(splitted[0]);
            right.push(splitted[1]);

        }
        var result = left.concat(right);
    };
</code></pre>

<p><strong>Update</strong></p>

<p>data inside data.json file has four teams with two members in each team in this form</p>

<pre><code>"109 200" = Team 1
"109 201" = Team 2
"102 202" = Team 3
"103 202" = Team 4
</code></pre>

<p>So now I have to compute the smallest number of people and it has to select one member from each team from this list and show their IDs. So the output for above would be</p>

<pre><code>109
202
</code></pre>

<p><strong>Latest update</strong></p>

<p>I am still waiting for help</p>

<p><strong>Solution</strong></p>

<p>Here is the solution with the help of AlexBEll and PAEz. I used solution below which was basically solved by AlexBell</p>

<pre><code>var data = [
 "1009 2000", 
 "1009 2001", 
 "1002 2002", 
 "1003 2002", 
 "1004 2003", 
 "1005 2004", 
 "1006 2005", 
 "1007 2006", 
 "1007 2007", 
 "1008 2008", 
 "1009 2008", 
 "1010 2009", 
 "1011 2010", 
 "1012 2010"      
];

var first = [], second = [], result = {}, out = '';

//Separe the ids
for(var i = 0; i &lt; data.length; i++){
    var el = data[i].split(' '); 
    first[i] = el[0];
    second[i] = el[1];
}

for(var k = 0; k &lt; first.length; k++){

    //Count the elements
    var nOfFirst = countElemnts(first, first[k]);
    var nOfSecond = countElemnts(second, second[k]);

    //If the first is in more that second take it
    if(nOfFirst &gt; nOfSecond){
        result[first[k]] = 0;
    //Else take the second        
    }else if(nOfFirst &lt; nOfSecond){
        result[second[k]] = 0;
    //If is only one take it    
    }else{
        result[first[k]] = 0;
    }

}

function countElemnts(arr, el){
    var count = 0;
    for(var j = 0; j &lt; arr.length; j++){
        if(arr[j] == el)
            count++;
    }
    //console.log(el+' : '+count);
    return count;
}

for(var n in result){
    out += 'The id n: '+n+' is in the list\n';
}

alert(out);
</code></pre>
