Steps
Parse URL arguments to JavaScript object
First step would be to parse this parameter to an object easy to manipulate. Other questions asked how to do this, so you will only have to search a bit to find which is best for you. The one I found first uses JQuery BBQ's deparam
function, which is the reverse for JQuery's param
function. Parsing your URL parameter this way is easy:
var params = $.deparam(urlParam);
Extract minimums from each array
Another answer (same method used here) showed how to add a function to the array prototype which would return the minimal element of the array.
Array.prototype.min = function() {
return Math.min.apply(null, this);
};
If you go with it, getting the lowest element of your array is simple:
var lowestUnits = params.units.min();
Alternately, if you do not wish to add it to your prototype, you could call it explicitely:
var lowestUnits = Math.min.apply(null, params.units);
Full code example
Concatenating the samples from other answers, here is would be how to go1:
Adding a min
function to Array's prototype
Array.prototype.min = function() {
return Math.min.apply(null, this);
};
// ...
var params = $.deparam('units[1]=5&grade[1]=1.25&units[2]=3&grade[2]=1.50&units[3]=2&grade[3]=2.50');
var lowestGrade = params.grade.min();
var lowestUnits = params.units.min();
Leaving prototype as is
var params = $.deparam('units[1]=5&grade[1]=1.25&units[2]=3&grade[2]=1.50&units[3]=2&grade[3]=2.50');
var lowestGrade = Math.min.apply(null, params.grade);
var lowestUnits = Math.min.apply(null, params.units);
1: Once again, JQuery BBQ's deparam
function is not the only available solution.