Q:

How to get minimum values with comparison in javascript

I want to obtain minimum value for a group/unique key in JavaScript
var allPriceData = $('#allPriceData').val();
//  alert (allPriceData);   
// Data 801||264||15:801||264||10:801||265||18:801||265||20:801||265||18        
var arr = allPriceData.split(':');

for(var j=0;j<arr.length;j++) {
    alert(arr[j]);
    var array = arr[j].split('||');

    for(var k=0;k<array.length;k++) {

    // Need Code Here for Required result:       
   }
 }

here is a sample array
264||15
264||10
265||18
265||20
265||22
Required Answer :
264||10
265||18
thanks...

A:

Done:
var energy = '264||0||10:265||0||0:266||265||1614.99:269||0||0:270||269||0';
alert(energy);

var small = ["264||0||15","265||0||0","268||265||20.99"];
alert(small);

var min_array = energy.split(':');
var sum = 0;
for(var r=0;r<min_array.length;r++) {
    var min_values = min_array[r].split('||');

    var n = 'false';
    for(var j=0;j<small.length;j++) {
        //  alert(x[j]);
        var temp = small[j].split('||');
        if (temp[0] == min_values[0] && temp[1] == min_values[1])
        {
            sum = parseFloat(sum) + parseFloat(temp[2]);
            n = 'true';         
        } 
        else if (temp[1] != 0 && temp[1] == min_values[1])
        {
            sum = parseFloat(sum) + parseFloat(temp[2]);
            n = 'true';
        }
    }
    if (n == 'false')
    {
        sum = parseFloat(sum) + parseFloat(min_values[2]);
    }
    alert('sum '+sum);
 }

