Git Product home page Git Product logo

playground's People

Contributors

halshing avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

playground's Issues

ArrayOfObjectsFilter Issue

Thanks for your ArrayOfObjectsFilter snippet, it's exactly what I was looking for.

One issue is that you are initializing the count variable before the for loops so the value is not getting reset to 0 and none of the items are being correctly matched after evaluating the first item.

I fixed it by initializing the count variable inside the matchesFiler function

Array.prototype.flexFilter = function(info) {
  
  // Set our variables
  var matchesFilter, matches = [];
  
  // Helper function to loop through the filter criteria to find matching values
  // Each filter criteria is treated as "AND". So each item must match all the filter criteria to be considered a match.
  // Multiple filter values in a filter field are treated as "OR" i.e. ["Blue", "Green"] will yield items matching a value of Blue OR Green.
  matchesFilter = function(item) {

   var count = 0;
  	
    for (var n = 0; n < info.length; n++) {
      if (info[n]["Values"].indexOf(item[info[n]["Field"]]) > -1) {
        count++;
      }
    }
    // If TRUE, then the current item in the array meets all the filter criteria
    return count == info.length;
  }

  // Loop through each item in the array
  for (var i = 0; i < this.length; i++) {

    // Determine if the current item matches the filter criteria
    if (matchesFilter(this[i])) {
      matches.push(this[i]);
    }

  }

  // Give us a new array containing the objects matching the filter criteria
  return matches;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.