DSContEd / IntroWebDevelopment

At the end of the course, students will be able to plan, design, and implement a web site using current standards and best practices.
1 stars 1 forks source link

Using the following function, please create a working example in jsbin #19

Open TonyGoodDay2 opened 7 years ago

TonyGoodDay2 commented 7 years ago

function filterGeoJSON(json, propertiesKey, value, operator) { / Operator "eq" equals "lt" less than "le" less than or equal "gt" greater than "ge" greather than or equal "ne" not equal /

var result = [];
var i = 0;

if (operator === "lt") {
    for (var filteredIndex in json) {
        if (json[filteredIndex].properties[

                propertiesKey] < value) {

            result[i] = json[filteredIndex];
            i++;
        }
    }

} else if (operator === "gt") {
    for (var filteredIndex in json) {
        if (json[filteredIndex].properties[

                propertiesKey] > value) {

            result[i] = json[filteredIndex];
            i++;
        }
    }

} else if (operator === "eq") {
    for (var filteredIndex in json) {
        if (json[filteredIndex].properties[

                propertiesKey] === value) {

            result[i] = json[filteredIndex];
            i++;
        }
    }

} else if (operator === "ne") {
    for (var filteredIndex in json) {
        if (json[filteredIndex].properties[
                propertiesKey] != value) {
            result[i] = json[filteredIndex];
            i++;
        }
    }

} else if (operator === "le") {
    for (var filteredIndex in json) {
        if (json[filteredIndex].properties[
                propertiesKey] <= value) {
            result[i] = json[filteredIndex];
            i++;
        }
    }

} else if (operator === "ge") {
    for (var filteredIndex in json) {
        if (json[filteredIndex].properties[
                propertiesKey] >= value) {
            result[i] = json[filteredIndex];
            i++;
        }
    }
}
return result;

}

cmitchell74 commented 7 years ago

YES!!! https://jsbin.com/sudabateca/edit?html,js,console

jjsahn commented 7 years ago

I was able to use the Haiti json file and got an output:

https://jsbin.com/riwavoneyu/edit?html,js,console

Thanks @cmitchell74 for the help :)

@jjsahn Not sure if this was the latest jsbin because I don't see the function being used. Perhaps this is an older version