halshing / playground Goto Github PK
View Code? Open in Web Editor NEWUtility and helper scripts and apps
Utility and helper scripts and apps
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;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.