Skip to content

Instantly share code, notes, and snippets.

@cojohn
Created February 17, 2012 18:40
Show Gist options
  • Save cojohn/1854772 to your computer and use it in GitHub Desktop.
Save cojohn/1854772 to your computer and use it in GitHub Desktop.
Is there a better way to test for a custom Object in an array of custom Objects?
// `id` is a custom Object and `Actor.getTips()` is an array of `id`s
Actor.prototype.hasTipped = function(id) {
return new RegExp(id.toString())
.test(this.getTips().toString());
}
/*
* Specifically, these are MongoDB ObjectIDs from the node-mongodb-native repository.
* Actor.getTips().indexOf(id) does not work because `===` returns false on, say,
* Actor.getTips()[0] === id.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment