Skip to content

Instantly share code, notes, and snippets.

@neokoenig
Created June 27, 2018 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neokoenig/e3a1e87ebf644d41f3ab2591a746a88e to your computer and use it in GitHub Desktop.
Save neokoenig/e3a1e87ebf644d41f3ab2591a746a88e to your computer and use it in GitHub Desktop.
ArrayFind vs ArrayFilter as Member functions
<cfscript>
products = [
{"sku": "prod_one", "title": "Product One"},
{"sku": "prod_two", "title": "Product Two"},
{"sku": "prod_three", "title": "Product Three"},
{"sku": "prod_four", "title": "Product Four"}
];
skuToFind="prod_two";
echo("========== Using Find as a Member Function");
f = products.find(function(el) {
return el.sku == skuToFind;
});
writeDump(f);
echo("========== Using Filter as a Member Function");
x = products.filter(function(el) {
return el.sku == skuToFind;
});
writeDump(x);
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment