Skip to content

Instantly share code, notes, and snippets.

@bradoyler
Created August 2, 2014 15:38
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 bradoyler/a8b675d07a0c468ac380 to your computer and use it in GitHub Desktop.
Save bradoyler/a8b675d07a0c468ac380 to your computer and use it in GitHub Desktop.
filter array & display time it occured
function findIds(arr, filterFn) {
var results = arr.filter(filterFn);
results.timestamp = new Date();
return result;
}
var ids = [0, 1, 2, 8, 4, 4, 5, 6, 7, 8, 9];
var filtered = findIds(ids, function(x) {
return (x == 8);
});
console.log(filtered); // Outputs: [8, 8, timestamp: Sat Aug 02 2014 11:36:13 GMT-0400 (EDT)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment