0

I'm unsure how else to write the title but it's about as close as I can get to what I'm after.

I have a calculator I'm trying to create that compares values in a number of arrays.

Each data object in my array has 34 rows, some of which have the same number/value in them.

At the minute if you select france, I only want 1 of each grade to show in the dropdown, so the number 1 would appear once.

If you select France and grade 1, I want the outputted value to say the lowest value in that range to the highest, in this case USA would output 3 to 5 does this make sense?

enter image description here

If so I'm wondering how I'd possibly do this?

JSFiddle

http://jsfiddle.net/R85Qj/

7
  • It would be easier to do if you add a numeric index to each row like ["3", "3", 3] Commented Feb 26, 2014 at 21:38
  • Thanks @NadeemAfana, I don't quite follow however, I've never used something like that Commented Feb 26, 2014 at 21:40
  • do you just need the grade drop down to be unique or is your q more complicated than that? Commented Feb 26, 2014 at 21:43
  • The grades have some sort of correlation, if you look at both arrays i the picture, In france, 1 is equal to 3 all the way up to 5.0 @RossG Commented Feb 26, 2014 at 21:45
  • If you add an extra number to each array: grades: [ ["1", "1", 1], ["1", "1", 1], ["1", "1", 1], ["2", "2", 2], ] you would be able to group matching values. This would make it easier to get unique list of your grades. Commented Feb 26, 2014 at 21:53

1 Answer 1

1

Does this help?

http://jsfiddle.net/R85Qj/2/

$("#convert").on("click", function () {
    var gradeIndex = $("#grade").val();
    var gradeConversion = "";
  /*  gradeConversion += "<span>" + countryGrades[countryGradesIndex].country + ": " + countryGrades[countryGradesIndex].grades[gradeIndex][1] + "</span>";*/
    var indexes = [];
    var countryIndex = $("#country").val();   
    var gradeValue = countryGrades[countryIndex].grades[gradeIndex][0];

    // find all indexes of gradeValue
    for(var i = 0; i < countryGrades[countryIndex].grades.length; i++) {
        if (countryGrades[countryIndex].grades[i][1] == gradeValue) {
             indexes.push(i);   
        }
    }

    allValues = [];

    for(var c = 0; c < countryGrades.length; c++) {
        gradeConversion += countryGrades[c].country + ":";
    for(i = 0; i < indexes.length; i++) {
        if (i == 0 || countryGrades[c].grades[indexes[i]][1] !=  countryGrades[c].grades[indexes[i-1]][1]) {
       gradeConversion += countryGrades[c].grades[indexes[i]][1] + " ";
        }
    }
   }


    $("#conversions").html(gradeConversion);
});
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for your input @NadeemAfana, it's not what I'm after however, I'll try and explain better.
If you select 1 in french, 1 is equal to USA 3, 4 and 5. So when you select French 1 it should output USA 3 to 5, does this make sense?
Thats halfway there @NadeemAfana! I just need to only show 1 value if theres multiple instances of it, so in france dropdown, there should be three 1 grades, just the 1
It does but the grades no longer matchup @NadeemAfana :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.